Skip to content

Commit dc9d0b8

Browse files
committed
fix: handle branch protection in release workflow
- Revert auto-bump for workflow_run trigger (can't push to protected branches) - Add clear notice messages when release is skipped due to existing tag - Require RELEASE_TOKEN secret (PAT with bypass permissions) for auto-bump - Provide helpful error messages when RELEASE_TOKEN is not configured To trigger a release: 1. Bump version in Cargo.toml before merging to main (recommended) 2. OR set up RELEASE_TOKEN secret and use workflow_dispatch with bump_type 3. OR push a tag directly (e.g., git tag v2.2.0 && git push origin v2.2.0)
1 parent 51496b7 commit dc9d0b8

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

.github/workflows/release.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,10 @@ jobs:
108108
109109
# Check if this version tag already exists
110110
if git tag -l "v$CURRENT_VERSION" | grep -q .; then
111-
echo "Tag v$CURRENT_VERSION already exists, auto-bumping patch version"
112-
# Auto-bump patch version
113-
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
114-
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
115-
echo "Auto-bumped to: $NEW_VERSION"
116-
echo "should_release=true" >> $GITHUB_OUTPUT
117-
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
118-
echo "needs_bump=true" >> $GITHUB_OUTPUT
111+
echo "::notice::Tag v$CURRENT_VERSION already exists. To create a new release, either:"
112+
echo "::notice:: 1. Bump the version in Cargo.toml before merging to main"
113+
echo "::notice:: 2. Use workflow_dispatch with bump_type to auto-bump and release"
114+
echo "should_release=false" >> $GITHUB_OUTPUT
119115
else
120116
echo "New version v$CURRENT_VERSION detected, will release"
121117
echo "should_release=true" >> $GITHUB_OUTPUT
@@ -129,14 +125,25 @@ jobs:
129125
echo "should_release=false" >> $GITHUB_OUTPUT
130126
131127
# Bump version in Cargo.toml if needed
128+
# Note: This job requires a PAT with bypass permissions to push to protected branches
129+
# Set the RELEASE_TOKEN secret to enable auto-bumping, otherwise bump version manually before release
132130
bump-version:
133131
needs: check
134132
if: needs.check.outputs.should_release == 'true' && needs.check.outputs.needs_bump == 'true'
135133
runs-on: ubuntu-latest
136134
steps:
135+
- name: Check for release token
136+
id: check-token
137+
run: |
138+
if [ -z "${{ secrets.RELEASE_TOKEN }}" ]; then
139+
echo "::error::Auto-bump requires RELEASE_TOKEN secret (a PAT with repo scope and bypass permissions)"
140+
echo "::error::Either set up RELEASE_TOKEN or bump the version in Cargo.toml before merging to main"
141+
exit 1
142+
fi
143+
137144
- uses: actions/checkout@v4
138145
with:
139-
token: ${{ secrets.GITHUB_TOKEN }}
146+
token: ${{ secrets.RELEASE_TOKEN }}
140147

141148
- name: Update Cargo.toml version
142149
run: |
@@ -154,7 +161,7 @@ jobs:
154161
git commit -m "chore: bump version to $VERSION [skip ci]"
155162
git push
156163
env:
157-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
158165

159166
build:
160167
needs: [check, bump-version]

0 commit comments

Comments
 (0)