-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3372d72
commit 7a16e91
Showing
2 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module.exports = async ({ github, context, exec }) => { | ||
const isPrerelease = process.env.PRERELEASE === 'true'; | ||
|
||
console.log('Step 1. Apply version changes to all packages'); | ||
const versionApplyArgs = ['version', 'apply', '--all', '--json']; | ||
if (isPrerelease) { | ||
versionApplyArgs.push('--prerelease'); | ||
} | ||
const { stdout: ndjson } = await exec.getExecOutput('yarn', versionApplyArgs); | ||
const versions = ndjson.split('\n').map((line) => JSON.parse(line)); | ||
console.log('Releasing versions:', versions); | ||
|
||
const versionStrings = versions.map((v) => `${v.ident}@${v.newVersion}`); | ||
|
||
console.log('Step 2. Create a release commit'); | ||
await exec.exec('git', ['add', '.']); | ||
await exec.exec('git', [ | ||
'commit', | ||
'-m', | ||
`chore: release ${versionStrings.join(', ')}`, | ||
// Commiting using the GitHub action bot | ||
// More info here: https://github.com/actions/checkout/issues/13#issuecomment-724415212 | ||
'--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"', | ||
]); | ||
await exec.exec('git', ['push', 'origin', `main`]); | ||
|
||
console.log('Step 3. Publish changed packages'); | ||
await exec.exec('yarn', [ | ||
'workspaces', | ||
'foreach', | ||
'-pt', | ||
'--since', | ||
context.ref, // Check diff of the release commit | ||
'npm', | ||
'publish', | ||
]); | ||
|
||
console.log('Step 4. Create release'); | ||
const { stdout: targetCommitish } = await exec.getExecOutput('git', [ | ||
'rev-parse', | ||
'HEAD', | ||
]); | ||
console.log(`Using commit ${targetCommitish} as release ref`); | ||
|
||
const release = await github.rest.repos.createRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag_name: `${versions[0].ident}@${versions[0].newVersion}`, | ||
target_commitish: targetCommitish, | ||
name: versionStrings.join(', '), | ||
prereleasee: isPrerelease, | ||
generate_release_notes: true, | ||
}); | ||
console.log('Release created:', release); | ||
}; |