Skip to content

Commit

Permalink
fix: Fix release process
Browse files Browse the repository at this point in the history
  • Loading branch information
Embraser01 committed Apr 17, 2024
1 parent 3372d72 commit 7a16e91
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
27 changes: 6 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,12 @@ jobs:
- name: Yarn install
run: yarn

- name: Apply version to packages
id: version-apply
run: yarn version apply -all ${{ inputs.prerelease && '--prerelease' }}

- name: Compute commit message
- name: Publish changed packages and create release
uses: actions/github-script@v7
id: commit-message
with:
result-encoding: string
script: |
return `chore: release ${versions.map((v) => `${v.ident}@${v.newVersion}`)}`;
# Commiting using the GitHub action bot
# More info here: https://github.com/actions/checkout/issues/13#issuecomment-724415212
- name: Create commit of changed files
run: |
git add .
git commit -m "${{ steps.commit-message.outputs.result }}" --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
git push
- name: Publish changed packages
run: yarn workspaces foreach -pt --since ${{ github.ref }} npm publish
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
PRERELEASE: ${{ inputs.prerelease }}
with:
script: |
const script = require('./scripts/release-from-ci.js')
await script({ github, context, exec });
55 changes: 55 additions & 0 deletions scripts/release-from-ci.js
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);
};

0 comments on commit 7a16e91

Please sign in to comment.