-
Notifications
You must be signed in to change notification settings - Fork 0
320 lines (270 loc) · 10.4 KB
/
auto-release.yml
File metadata and controls
320 lines (270 loc) · 10.4 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
name: Auto Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
channel:
description: 'Release channel'
required: true
default: 'stable'
type: choice
options:
- stable
- beta
- alpha
permissions:
contents: write
id-token: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
NODE_VERSION: '20'
jobs:
detect-release:
name: Detect Release
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
release_type: ${{ steps.check.outputs.release_type }}
channel: ${{ steps.check.outputs.channel }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for release commit
id: check
run: |
# Manual workflow dispatch
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should_release=true" >> $GITHUB_OUTPUT
echo "release_type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT
echo "channel=${{ github.event.inputs.channel }}" >> $GITHUB_OUTPUT
echo "Manual release triggered: ${{ github.event.inputs.release_type }} (${{ github.event.inputs.channel }})"
exit 0
fi
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Commit: $COMMIT_MSG"
# Skip for version bumps and dependency updates
if [[ "$COMMIT_MSG" =~ \[skip\ ci\] ]] || \
[[ "$COMMIT_MSG" =~ ^chore:\ bump\ version ]] || \
[[ "$COMMIT_MSG" =~ ^chore\(deps ]] || \
[[ "$COMMIT_MSG" =~ ^Merge\ pull\ request.*dependabot ]]; then
echo "should_release=false" >> $GITHUB_OUTPUT
echo "Skipping: maintenance commit"
exit 0
fi
# Use sync-versions.js for semantic detection
RELEASE_OUTPUT=$(node scripts/sync-versions.js detect 2>&1)
if echo "$RELEASE_OUTPUT" | grep -q "should_release=true"; then
echo "$RELEASE_OUTPUT" >> $GITHUB_OUTPUT
echo "Release detected from commit"
else
echo "should_release=false" >> $GITHUB_OUTPUT
echo "No release pattern in commit"
fi
bump-version:
name: Bump Version
runs-on: ubuntu-latest
needs: detect-release
if: needs.detect-release.outputs.should_release == 'true'
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Bump version
id: bump
run: |
NEW_VERSION=$(node scripts/sync-versions.js release ${{ needs.detect-release.outputs.release_type }} ${{ needs.detect-release.outputs.channel }})
if [ -z "$NEW_VERSION" ]; then
echo "Failed to bump version"
exit 1
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumped to: $NEW_VERSION"
- name: Commit version bump
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add packages/*/package.json
if ! git diff --staged --quiet; then
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
git push || echo "Push blocked by branch rules, continuing with local bump"
else
echo "No changes to commit"
fi
validate:
name: Validate
runs-on: ubuntu-latest
needs: [detect-release, bump-version]
if: needs.detect-release.outputs.should_release == 'true'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: Re-apply version bump
run: node scripts/sync-versions.js release ${{ needs.detect-release.outputs.release_type }} ${{ needs.detect-release.outputs.channel }} > /dev/null
- run: npm ci
- run: npx turbo run typecheck
- run: npx turbo run test
- run: npx turbo run build
publish:
name: Publish to npm
needs: [detect-release, bump-version, validate]
if: needs.detect-release.outputs.should_release == 'true' && needs.validate.result == 'success'
runs-on: ubuntu-latest
environment: npm-publish
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
registry-url: https://registry.npmjs.org
- name: Upgrade npm for OIDC support
run: npm install -g npm@latest
- name: Re-apply version bump
run: node scripts/sync-versions.js release ${{ needs.detect-release.outputs.release_type }} ${{ needs.detect-release.outputs.channel }} > /dev/null
- run: npm ci
- run: npx turbo run build
- name: Publish @glincker/geo-audit
working-directory: packages/geo-audit
run: |
VERSION=${{ needs.bump-version.outputs.new_version }}
if npm view @glincker/geo-audit@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists, skipping"
else
npm publish --provenance --access public
fi
- name: Publish @glincker/geo-seo
working-directory: packages/geo-seo
run: |
VERSION=${{ needs.bump-version.outputs.new_version }}
if npm view @glincker/geo-seo@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists, skipping"
else
npm publish --provenance --access public
fi
- name: Publish @glincker/geomark
working-directory: packages/geomark
run: |
VERSION=${{ needs.bump-version.outputs.new_version }}
if npm view @glincker/geomark@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists, skipping"
else
npm publish --provenance --access public
fi
- name: Publish @glincker/geokit
working-directory: packages/geokit
run: |
VERSION=${{ needs.bump-version.outputs.new_version }}
if npm view @glincker/geokit@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists, skipping"
else
npm publish --provenance --access public
fi
github-release:
name: GitHub Release
needs: [detect-release, bump-version, publish]
if: needs.detect-release.outputs.should_release == 'true' && needs.publish.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Create git tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
TAG_NAME="v${{ needs.bump-version.outputs.new_version }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, skipping"
else
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
echo "Created tag $TAG_NAME"
fi
- name: Generate release notes
id: notes
run: |
VERSION="${{ needs.bump-version.outputs.new_version }}"
CHANNEL="${{ needs.detect-release.outputs.channel }}"
# Get changelog from commits since last tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | grep -E "^- (feat|fix|perf|refactor|revert)" | head -15 || echo "- Version bump")
else
CHANGELOG="- Initial release"
fi
cat > release_notes.md << EOF
## v${VERSION}
### Installation
\`\`\`bash
npm install @glincker/geokit@${VERSION}
# Or individual packages:
npm install @glincker/geo-audit@${VERSION}
npm install @glincker/geo-seo@${VERSION}
npm install @glincker/geomark@${VERSION}
\`\`\`
### Changes
${CHANGELOG}
### Packages
| Package | Version |
|---------|---------|
| @glincker/geo-audit | ${VERSION} |
| @glincker/geo-seo | ${VERSION} |
| @glincker/geomark | ${VERSION} |
| @glincker/geokit | ${VERSION} |
---
*Auto-released from conventional commit*
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.bump-version.outputs.new_version }}
name: v${{ needs.bump-version.outputs.new_version }}
body_path: release_notes.md
draft: false
prerelease: ${{ needs.detect-release.outputs.channel != 'stable' }}
summary:
name: Release Summary
runs-on: ubuntu-latest
needs: [detect-release, bump-version, validate, publish, github-release]
if: always() && needs.detect-release.outputs.should_release == 'true'
steps:
- name: Summary
run: |
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** v${{ needs.bump-version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Type:** ${{ needs.detect-release.outputs.release_type }}" >> $GITHUB_STEP_SUMMARY
echo "**Channel:** ${{ needs.detect-release.outputs.channel }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Step | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Validate | ${{ needs.validate.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Publish | ${{ needs.publish.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| GitHub Release | ${{ needs.github-release.result }} |" >> $GITHUB_STEP_SUMMARY