|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +/** |
| 4 | + * Creates a GitHub preview release and uploads tgz assets. |
| 5 | + * |
| 6 | + * @param {Object} params |
| 7 | + * @param {import('@octokit/rest').Octokit} params.github - Octokit instance |
| 8 | + * @param {Object} params.context - GitHub Actions context |
| 9 | + * @param {string} params.version - Version string (e.g., "0.0.1-preview.1") |
| 10 | + * @param {string} params.distDir - Directory containing tgz files |
| 11 | + */ |
| 12 | +export async function createPreviewRelease({ github, context, version, distDir }) { |
| 13 | + const fs = await import('fs'); |
| 14 | + const path = await import('path'); |
| 15 | + |
| 16 | + const tagName = `v${version}`; |
| 17 | + |
| 18 | + const releaseBody = `## Preview Release ${tagName} |
| 19 | +
|
| 20 | +### Installation |
| 21 | +
|
| 22 | +Download both tgz files and install them together: |
| 23 | +
|
| 24 | +\`\`\`bash |
| 25 | +npm install ./salesforce-b2c-tooling-sdk-${version}.tgz \\ |
| 26 | + ./salesforce-b2c-cli-${version}.tgz |
| 27 | +\`\`\` |
| 28 | +
|
| 29 | +Or install globally: |
| 30 | +
|
| 31 | +\`\`\`bash |
| 32 | +npm install -g ./salesforce-b2c-tooling-sdk-${version}.tgz \\ |
| 33 | + ./salesforce-b2c-cli-${version}.tgz |
| 34 | +\`\`\` |
| 35 | +
|
| 36 | +> **Note:** Both packages must be installed together since the CLI depends on the SDK. |
| 37 | +`; |
| 38 | + |
| 39 | + // Create the release |
| 40 | + const release = await github.rest.repos.createRelease({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + tag_name: tagName, |
| 44 | + name: tagName, |
| 45 | + prerelease: true, |
| 46 | + generate_release_notes: true, |
| 47 | + body: releaseBody, |
| 48 | + }); |
| 49 | + |
| 50 | + console.log(`Created release: ${release.data.html_url}`); |
| 51 | + |
| 52 | + // Upload all tgz files from dist/ |
| 53 | + const files = fs.readdirSync(distDir).filter((f) => f.endsWith('.tgz')); |
| 54 | + |
| 55 | + for (const file of files) { |
| 56 | + const filePath = path.join(distDir, file); |
| 57 | + const fileData = fs.readFileSync(filePath); |
| 58 | + |
| 59 | + console.log(`Uploading ${file}...`); |
| 60 | + |
| 61 | + await github.rest.repos.uploadReleaseAsset({ |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + release_id: release.data.id, |
| 65 | + name: file, |
| 66 | + data: fileData, |
| 67 | + }); |
| 68 | + |
| 69 | + console.log(`Uploaded ${file}`); |
| 70 | + } |
| 71 | + |
| 72 | + console.log(`Release complete: ${release.data.html_url}`); |
| 73 | + return release.data.html_url; |
| 74 | +} |
0 commit comments