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