Skip to content

Commit fe63b36

Browse files
crrowclaude
andcommitted
feat(ci): auto release PR on push to main
Replace tag-triggered workflow with release-plz style automation: - Push to main → git-cliff detects next version → release PR created - Merge release PR → tag + GitHub Release published - Add bump rules to cliff.toml for version detection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 47cd78b commit fe63b36

File tree

2 files changed

+56
-69
lines changed

2 files changed

+56
-69
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,146 +2,129 @@ name: Release
22

33
on:
44
push:
5-
branches:
6-
- main
7-
tags:
8-
- "v[0-9]*"
5+
branches: [main]
96

107
permissions:
118
contents: write
129
pull-requests: write
1310

1411
jobs:
15-
prepare-release-pr:
16-
name: Prepare release PR
17-
if: startsWith(github.ref, 'refs/tags/')
12+
release-pr:
13+
name: Create or update release PR
1814
runs-on: ubuntu-latest
15+
# Skip release commits to avoid infinite loops
16+
if: "!startsWith(github.event.head_commit.message, 'chore(release):')"
1917
steps:
20-
- name: Extract version from tag
21-
id: version
22-
run: |
23-
TAG="${GITHUB_REF#refs/tags/}"
24-
VERSION="${TAG#v}"
25-
echo "tag=$TAG" >> $GITHUB_OUTPUT
26-
echo "version=$VERSION" >> $GITHUB_OUTPUT
27-
2818
- name: Checkout
2919
uses: actions/checkout@v4
3020
with:
3121
fetch-depth: 0
3222

23+
- name: Determine next version
24+
id: next
25+
run: |
26+
set -euo pipefail
27+
28+
# Get current version from version.go
29+
CURRENT=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go)
30+
echo "current=$CURRENT" >> $GITHUB_OUTPUT
31+
32+
# Use git-cliff to calculate the bumped version
33+
pip install git-cliff >/dev/null 2>&1 || true
34+
NEXT=$(git cliff --bumped-version 2>/dev/null | sed 's/^v//')
35+
36+
if [ -z "$NEXT" ] || [ "$NEXT" = "$CURRENT" ]; then
37+
echo "No version bump needed"
38+
echo "bump=false" >> $GITHUB_OUTPUT
39+
exit 0
40+
fi
41+
42+
echo "version=$NEXT" >> $GITHUB_OUTPUT
43+
echo "tag=v$NEXT" >> $GITHUB_OUTPUT
44+
echo "bump=true" >> $GITHUB_OUTPUT
45+
echo "Bumping $CURRENT -> $NEXT"
46+
3347
- name: Update version.go
48+
if: steps.next.outputs.bump == 'true'
3449
run: |
35-
VERSION="${{ steps.version.outputs.version }}"
50+
VERSION="${{ steps.next.outputs.version }}"
3651
sed -i "s/const Version = \".*\"/const Version = \"$VERSION\"/" version.go
3752
3853
- name: Generate changelog
54+
if: steps.next.outputs.bump == 'true'
3955
uses: orhun/git-cliff-action@v4
4056
with:
4157
config: cliff.toml
42-
args: --tag ${{ steps.version.outputs.tag }}
58+
args: --tag ${{ steps.next.outputs.tag }}
4359
env:
4460
OUTPUT: CHANGELOG.md
4561

46-
- name: Check for modifications
47-
id: changes
48-
run: |
49-
if git diff --quiet; then
50-
echo "changes=false" >> $GITHUB_OUTPUT
51-
else
52-
echo "changes=true" >> $GITHUB_OUTPUT
53-
fi
54-
5562
- name: Create release PR
56-
if: steps.changes.outputs.changes == 'true'
63+
if: steps.next.outputs.bump == 'true'
5764
uses: peter-evans/create-pull-request@v6
5865
with:
5966
token: ${{ secrets.GITHUB_TOKEN }}
6067
base: main
61-
commit-message: "chore(release): bump version to ${{ steps.version.outputs.version }}"
62-
branch: release/${{ steps.version.outputs.tag }}
63-
title: "chore(release): ${{ steps.version.outputs.tag }}"
68+
commit-message: "chore(release): bump version to ${{ steps.next.outputs.version }}"
69+
branch: release/next
70+
title: "chore(release): v${{ steps.next.outputs.version }}"
6471
body: |
65-
## Release `${{ steps.version.outputs.tag }}`
72+
## Release `v${{ steps.next.outputs.version }}`
6673
67-
Automated release preparation triggered by tag push.
74+
Automated release preparation.
6875
6976
### Changes
70-
- Update `version.go` to `${{ steps.version.outputs.version }}`
77+
- Update `version.go` to `${{ steps.next.outputs.version }}`
7178
- Refresh `CHANGELOG.md`
7279
73-
### What happens after merge?
74-
Merging this PR will automatically:
75-
1. Create a GitHub Release for `${{ steps.version.outputs.tag }}`
76-
2. Update the release tag to point to the merge commit
80+
### After merge
81+
A GitHub Release with tag `v${{ steps.next.outputs.version }}` will be created automatically.
7782
add-paths: |
7883
version.go
7984
CHANGELOG.md
8085
labels: release
8186

8287
publish-release:
8388
name: Publish GitHub release
84-
if: github.ref == 'refs/heads/main'
8589
runs-on: ubuntu-latest
90+
# Only run on release commits (merged release PR)
91+
if: startsWith(github.event.head_commit.message, 'chore(release):')
8692
steps:
8793
- name: Checkout
8894
uses: actions/checkout@v4
8995
with:
9096
fetch-depth: 0
9197

92-
- name: Detect release commit
98+
- name: Extract version
9399
id: release
94100
run: |
95101
set -euo pipefail
96-
BEFORE="${{ github.event.before }}"
97-
AFTER="${{ github.sha }}"
98-
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
99-
BEFORE="$(git rev-parse "${AFTER}^" 2>/dev/null || echo "")"
100-
fi
101-
102-
if [ -z "$BEFORE" ]; then
103-
echo "run=false" >> $GITHUB_OUTPUT
104-
exit 0
105-
fi
106-
107-
if git diff --quiet "$BEFORE" "$AFTER" -- version.go; then
108-
echo "run=false" >> $GITHUB_OUTPUT
109-
exit 0
110-
fi
111-
112102
VERSION=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go)
113103
if [ -z "$VERSION" ]; then
114-
echo "Unable to determine version from version.go" >&2
104+
echo "Unable to determine version" >&2
115105
exit 1
116106
fi
117-
118-
echo "run=true" >> $GITHUB_OUTPUT
119107
echo "version=$VERSION" >> $GITHUB_OUTPUT
120108
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
121109
122110
- name: Configure git
123-
if: steps.release.outputs.run == 'true'
124111
run: |
125112
git config user.name "github-actions[bot]"
126113
git config user.email "github-actions[bot]@users.noreply.github.com"
127114
128-
- name: Update release tag
129-
if: steps.release.outputs.run == 'true'
115+
- name: Create and push tag
130116
run: |
131117
TAG="${{ steps.release.outputs.tag }}"
132-
git fetch origin --tags
133-
git tag -a "$TAG" -f -m "Release $TAG"
134-
git push origin "$TAG" --force
118+
git tag -a "$TAG" -m "Release $TAG"
119+
git push origin "$TAG"
135120
136121
- name: Get previous tag
137-
if: steps.release.outputs.run == 'true'
138122
id: prev_tag
139123
run: |
140124
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
141125
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
142126
143-
- name: Generate changelog
144-
if: steps.release.outputs.run == 'true'
127+
- name: Generate release notes
145128
id: changelog
146129
uses: orhun/git-cliff-action@v4
147130
with:
@@ -152,13 +135,12 @@ jobs:
152135
OUTPUT: /tmp/RELEASE_CHANGELOG.md
153136

154137
- name: Create GitHub Release
155-
if: steps.release.outputs.run == 'true'
156138
uses: softprops/action-gh-release@v2
157139
with:
158140
tag_name: ${{ steps.release.outputs.tag }}
159141
body: ${{ steps.changelog.outputs.content }}
160142
draft: false
161-
prerelease: ${{ contains(steps.release.outputs.tag, '-alpha') || contains(steps.release.outputs.tag, '-beta') || contains(steps.release.outputs.tag, '-rc') }}
143+
prerelease: false
162144
generate_release_notes: false
163145
env:
164146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cliff.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ commit_parsers = [
4242
{ message = "^chore|^ci", group = "⚙️ Miscellaneous" },
4343
{ message = "^revert", group = "◀️ Revert" },
4444
]
45+
# Bump rules for automatic version detection
46+
[bump]
47+
features_always_bump_minor = true
48+
breaking_always_bump_major = true
49+
4550
protect_breaking_commits = false
4651
filter_commits = false
4752
topo_order = false

0 commit comments

Comments
 (0)