Skip to content

Commit ce4bb35

Browse files
roottoolclaude
andauthored
ci: improve release workflow automation (#28)
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent cb38a4b commit ce4bb35

File tree

3 files changed

+110
-44
lines changed

3 files changed

+110
-44
lines changed

.github/release.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ changelog:
44
- "ignore for release"
55

66
categories:
7-
- title: Security Fixes
8-
labels: ["Type: Security", "security"]
97
- title: Breaking Changes
10-
labels: ["Type: Breaking Change"]
11-
- title: Features
12-
labels: ["Type: enhancement"]
8+
labels: ["Type: Breaking Change", "breaking change"]
139
- title: Bug Fixes
14-
labels: ["Type: bug"]
10+
labels: ["Type: bug", "bug"]
1511
- title: Documentation
1612
labels: ["Type: Documentation", "documentation"]
1713
- title: CI
1814
labels: ["Type: CI", "ci"]
15+
- title: Security Fixes
16+
labels: ["Type: Security", "security"]
1917
- title: Dependency Updates
2018
labels: ["Type: Dependencies", "dependencies"]
2119
- title: Other Changes
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Prepare Release PR
2+
run-name: "Prepare release ${{ inputs.release-version }} (${{ github.ref_name }})"
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
release-version:
8+
description: Select release semantic version.
9+
required: true
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
28+
jobs:
29+
prepare:
30+
name: Prepare Release PR
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 10
33+
steps:
34+
- name: Checkout Repository
35+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
36+
with:
37+
persist-credentials: false
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
41+
with:
42+
node-version: lts/*
43+
44+
- name: Bump version
45+
run: |
46+
npm version "${{ inputs.release-version }}" --no-git-tag-version
47+
48+
- name: Read version
49+
id: version
50+
run: |
51+
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
52+
53+
- name: Create release branch
54+
run: |
55+
git checkout -b release/v${{ steps.version.outputs.version }}
56+
57+
- name: Commit version change
58+
run: |
59+
git config user.name "github-actions"
60+
git config user.email "[email protected]"
61+
git add package.json
62+
git commit -m "chore(release): v${{ steps.version.outputs.version }}"
63+
git push origin HEAD
64+
65+
- name: Create Pull Request
66+
run: |
67+
gh pr create \
68+
--title "release: v${{ steps.version.outputs.version }}" \
69+
--body "Release v${{ steps.version.outputs.version }}" \
70+
--base main \
71+
--head release/v${{ steps.version.outputs.version }} \
72+
--label "ignore for release"
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,26 @@ name: Publish
22
run-name: "${{ github.workflow }} (${{ github.ref_name }})"
33

44
on:
5-
push:
6-
tags:
7-
- v*.*.*
5+
workflow_dispatch:
86

97
defaults:
108
run:
119
shell: bash
1210

13-
jobs:
14-
validate:
15-
name: Validate Version
16-
runs-on: ubuntu-latest
17-
timeout-minutes: 5
18-
steps:
19-
- name: Checkout Repository
20-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
21-
with:
22-
persist-credentials: false
23-
24-
- name: Extract version from tag
25-
id: tag_version
26-
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
27-
28-
- name: Extract version from package.json
29-
id: pkg_version
30-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
3114

32-
- name: Compare versions
33-
run: |
34-
if [ "${{ steps.tag_version.outputs.version }}" != "${{ steps.pkg_version.outputs.version }}" ]; then
35-
echo "Error: Tag version (${{ steps.tag_version.outputs.version }}) does not match package.json version (${{ steps.pkg_version.outputs.version }})"
36-
exit 1
37-
fi
38-
echo "Version validation successful: v${{ steps.pkg_version.outputs.version }}"
15+
permissions:
16+
contents: write
17+
id-token: write
3918

40-
publish-npm:
41-
name: Publish to npm
19+
jobs:
20+
publish:
21+
name: Publish package
4222
runs-on: ubuntu-latest
43-
timeout-minutes: 5
44-
permissions:
45-
contents: write
46-
id-token: write
23+
timeout-minutes: 10
4724
environment: npm-registry
48-
needs: [validate]
4925
steps:
5026
- name: Checkout Repository
5127
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
@@ -64,12 +40,30 @@ jobs:
6440
- name: Install latest npm
6541
run: npm install -g npm@latest
6642

43+
- name: Read version
44+
id: version
45+
run: |
46+
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
47+
48+
- name: Ensure version not published
49+
run: |
50+
VERSION="v${{ steps.version.outputs.version }}"
51+
52+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
53+
echo "Tag $VERSION already exists"
54+
exit 1
55+
fi
56+
6757
- name: Publish to npm
6858
run: npm publish --provenance --access public
6959

60+
- name: Create and push tag
61+
run: |
62+
git tag "v${{ steps.version.outputs.version }}"
63+
git push origin "v${{ steps.version.outputs.version }}"
64+
7065
- name: Create GitHub Release
71-
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
72-
with:
73-
generate_release_notes: true
66+
run: |
67+
gh release create "v${{ steps.version.outputs.version }}" --generate-notes
7468
env:
7569
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)