Skip to content

Commit e47878c

Browse files
fix: Fix release process (#53)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3372d72 commit e47878c

File tree

5 files changed

+89
-26
lines changed

5 files changed

+89
-26
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,12 @@ jobs:
2727
- name: Yarn install
2828
run: yarn
2929

30-
- name: Apply version to packages
31-
id: version-apply
32-
run: yarn version apply -all ${{ inputs.prerelease && '--prerelease' }}
33-
34-
- name: Compute commit message
30+
- name: Publish changed packages and create release
3531
uses: actions/github-script@v7
36-
id: commit-message
37-
with:
38-
result-encoding: string
39-
script: |
40-
return `chore: release ${versions.map((v) => `${v.ident}@${v.newVersion}`)}`;
41-
42-
# Commiting using the GitHub action bot
43-
# More info here: https://github.com/actions/checkout/issues/13#issuecomment-724415212
44-
- name: Create commit of changed files
45-
run: |
46-
git add .
47-
git commit -m "${{ steps.commit-message.outputs.result }}" --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
48-
git push
49-
50-
- name: Publish changed packages
51-
run: yarn workspaces foreach -pt --since ${{ github.ref }} npm publish
5232
env:
5333
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
34+
PRERELEASE: ${{ inputs.prerelease }}
35+
with:
36+
script: |
37+
const script = require('./scripts/release-from-ci.js')
38+
await script({ github, context, exec });

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

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

7-
## 3.1.7 - 2024-02-23
7+
## 3.1.7 - 2024-02-23, 2024-04-17
8+
9+
- Automated release process
810

911
## 3.1.6 - 2024-02-23
1012

packages/typoas-cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typoas/cli",
3-
"version": "3.1.5",
3+
"version": "3.1.6-rc.2",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
@@ -40,5 +40,6 @@
4040
"typoas-cli": "./lib/bin.js"
4141
},
4242
"types": "./lib/index.d.ts"
43-
}
43+
},
44+
"stableVersion": "3.1.5"
4445
}

packages/typoas-generator/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typoas/generator",
3-
"version": "3.1.5",
3+
"version": "3.1.6-rc.2",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
@@ -40,5 +40,6 @@
4040
"publishConfig": {
4141
"main": "./lib/index.js",
4242
"types": "./lib/index.d.ts"
43-
}
43+
},
44+
"stableVersion": "3.1.5"
4445
}

scripts/release-from-ci.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)