|
| 1 | +module.exports = async ({ github, context, exec }) => { |
| 2 | + const isPrerelease = process.env.PRERELEASE === 'true'; |
| 3 | + |
| 4 | + console.log('Step 1. Apply version changes to all packages'); |
| 5 | + const versionApplyArgs = ['version', 'apply', '--all', '--json']; |
| 6 | + if (isPrerelease) { |
| 7 | + versionApplyArgs.push('--prerelease'); |
| 8 | + } |
| 9 | + const { stdout: ndjson } = await exec.getExecOutput('yarn', versionApplyArgs); |
| 10 | + const versions = ndjson |
| 11 | + .split('\n') |
| 12 | + .filter(Boolean) |
| 13 | + .map((line) => JSON.parse(line)); |
| 14 | + console.log('Releasing versions:', versions); |
| 15 | + |
| 16 | + const versionStrings = versions.map((v) => `${v.ident}@${v.newVersion}`); |
| 17 | + |
| 18 | + console.log('Step 2. Create a release commit'); |
| 19 | + |
| 20 | + // Commiting using the GitHub action bot |
| 21 | + // More info here: https://github.com/actions/checkout/issues/13#issuecomment-724415212 |
| 22 | + await exec.exec('git', [ |
| 23 | + 'config', |
| 24 | + '--global', |
| 25 | + 'user.email', |
| 26 | + '41898282+github-actions[bot]@users.noreply.github.com', |
| 27 | + ]); |
| 28 | + await exec.exec('git', [ |
| 29 | + 'config', |
| 30 | + '--global', |
| 31 | + 'user.name', |
| 32 | + 'github-actions[bot]', |
| 33 | + ]); |
| 34 | + |
| 35 | + await exec.exec('git', ['add', '.']); |
| 36 | + await exec.exec('git', [ |
| 37 | + 'commit', |
| 38 | + '-m', |
| 39 | + `chore: release ${versionStrings.join(', ')}`, |
| 40 | + ]); |
| 41 | + await exec.exec('git', [ |
| 42 | + 'push', |
| 43 | + 'origin', |
| 44 | + process.env.GITHUB_REF_NAME || `main`, |
| 45 | + ]); |
| 46 | + |
| 47 | + console.log('Step 3. Publish changed packages'); |
| 48 | + await exec.exec('yarn', [ |
| 49 | + 'workspaces', |
| 50 | + 'foreach', |
| 51 | + '-Apt', |
| 52 | + ...versions.flatMap((v) => ['--include', v.ident]), |
| 53 | + 'npm', |
| 54 | + 'publish', |
| 55 | + ]); |
| 56 | + |
| 57 | + console.log('Step 4. Create release'); |
| 58 | + const { stdout: targetCommitish } = await exec.getExecOutput('git', [ |
| 59 | + 'rev-parse', |
| 60 | + 'HEAD', |
| 61 | + ]); |
| 62 | + console.log(`Using commit ${targetCommitish} as release ref`); |
| 63 | + |
| 64 | + const release = await github.rest.repos.createRelease({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + tag_name: `${versions[0].ident}@${versions[0].newVersion}`, |
| 68 | + target_commitish: targetCommitish.trim(), |
| 69 | + name: versionStrings.join(', '), |
| 70 | + prereleasee: isPrerelease, |
| 71 | + generate_release_notes: true, |
| 72 | + }); |
| 73 | + console.log('Release created:', release); |
| 74 | +}; |
0 commit comments