Skip to content

Commit b353c94

Browse files
committed
chore: create release from Github Actions
1 parent 4d78e76 commit b353c94

6 files changed

Lines changed: 109 additions & 1290 deletions

File tree

.github/workflows/release.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options: [patch, minor, major]
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: Guard — owner only
20+
if: github.actor != github.repository_owner
21+
run: |
22+
echo "Only the repository owner can trigger releases."
23+
exit 1
24+
25+
- name: Checkout
26+
uses: actions/checkout@v6
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Setup Node 24
31+
uses: actions/setup-node@v6
32+
with:
33+
node-version: '24'
34+
35+
- name: Configure git
36+
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "github-actions[bot]@users.noreply.github.com"
39+
40+
- name: Bump version
41+
env:
42+
BUMP: ${{ github.event.inputs.bump }}
43+
run: npm version "$BUMP" --no-git-tag-version
44+
45+
- name: Capture new version
46+
id: version
47+
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
48+
49+
- name: Generate changelog
50+
run: |
51+
node -e "
52+
const { execSync } = require('child_process');
53+
const fs = require('fs');
54+
55+
const lastTag = execSync('git describe --tags --abbrev=0').toString().trim();
56+
const log = execSync('git log ' + lastTag + '..HEAD --format=%s').toString().trim();
57+
58+
const types = [
59+
['feat', '### Features'],
60+
['fix', '### Bug Fixes'],
61+
['refactor', '### Refactoring'],
62+
['revert', '### Reverts'],
63+
['perf', '### Performance'],
64+
];
65+
const typeMap = Object.fromEntries(types.map(([k, v]) => [k, v]));
66+
67+
const pattern = /^(\w+)(\(.+?\))?(!)?: (.+)$/;
68+
const groups = {};
69+
70+
for (const line of log.split('\n')) {
71+
const m = line.match(pattern);
72+
if (!m) continue;
73+
const type = m[1];
74+
const scope = m[2] ? m[2].slice(1, -1) : null;
75+
const msg = m[4];
76+
const label = typeMap[type];
77+
if (!label) continue;
78+
if (!groups[type]) groups[type] = [];
79+
groups[type].push(scope ? '- **' + scope + '**: ' + msg : '- ' + msg);
80+
}
81+
82+
const sections = types
83+
.filter(([k]) => groups[k])
84+
.map(([k, header]) => header + '\n' + groups[k].join('\n'))
85+
.join('\n\n');
86+
87+
const body = sections || '_No conventional commits found since last release._';
88+
fs.writeFileSync('CHANGELOG_BODY.md', body);
89+
console.log('Changelog written.');
90+
"
91+
92+
- name: Commit, tag, and push
93+
env:
94+
VERSION: ${{ steps.version.outputs.version }}
95+
run: |
96+
git add package.json app/package.json
97+
git commit -m "[Bumped Version] ${VERSION}"
98+
git push origin main
99+
git tag "${VERSION}"
100+
git push origin "${VERSION}"
101+
102+
- name: Create GitHub Release
103+
env:
104+
GH_TOKEN: ${{ github.token }}
105+
VERSION: ${{ steps.version.outputs.version }}
106+
run: gh release create "${VERSION}" --notes-file CHANGELOG_BODY.md --title "${VERSION}"

0 commit comments

Comments
 (0)