Skip to content

Commit

Permalink
fix: Fix release process (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Embraser01 and github-actions[bot] authored Apr 17, 2024
1 parent 3372d72 commit e47878c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 26 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 });
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

- Add `-p,--prettier` option to the cli to format the generated code with prettier [#51](https://github.com/Embraser01/typoas/pull/51)

## 3.1.7 - 2024-02-23
## 3.1.7 - 2024-02-23, 2024-04-17

- Automated release process

## 3.1.6 - 2024-02-23

Expand Down
5 changes: 3 additions & 2 deletions packages/typoas-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typoas/cli",
"version": "3.1.5",
"version": "3.1.6-rc.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,5 +40,6 @@
"typoas-cli": "./lib/bin.js"
},
"types": "./lib/index.d.ts"
}
},
"stableVersion": "3.1.5"
}
5 changes: 3 additions & 2 deletions packages/typoas-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typoas/generator",
"version": "3.1.5",
"version": "3.1.6-rc.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,5 +40,6 @@
"publishConfig": {
"main": "./lib/index.js",
"types": "./lib/index.d.ts"
}
},
"stableVersion": "3.1.5"
}
74 changes: 74 additions & 0 deletions scripts/release-from-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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')
.filter(Boolean)
.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');

// Commiting using the GitHub action bot
// More info here: https://github.com/actions/checkout/issues/13#issuecomment-724415212
await exec.exec('git', [
'config',
'--global',
'user.email',
'41898282+github-actions[bot]@users.noreply.github.com',
]);
await exec.exec('git', [
'config',
'--global',
'user.name',
'github-actions[bot]',
]);

await exec.exec('git', ['add', '.']);
await exec.exec('git', [
'commit',
'-m',
`chore: release ${versionStrings.join(', ')}`,
]);
await exec.exec('git', [
'push',
'origin',
process.env.GITHUB_REF_NAME || `main`,
]);

console.log('Step 3. Publish changed packages');
await exec.exec('yarn', [
'workspaces',
'foreach',
'-Apt',
...versions.flatMap((v) => ['--include', v.ident]),
'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.trim(),
name: versionStrings.join(', '),
prereleasee: isPrerelease,
generate_release_notes: true,
});
console.log('Release created:', release);
};

0 comments on commit e47878c

Please sign in to comment.