Skip to content

Commit 88c6bf7

Browse files
committed
fix(release): checkout main branch before pushing version bump
The release workflow was failing because the release event checks out the repository at the tag (detached HEAD state), not on the main branch. When the workflow tried to 'git push origin main', it failed with 'error: src refspec main does not match any'. This fix adds a step to explicitly checkout the main branch after the initial checkout, ensuring we're on a proper branch before making and pushing version bump commits.
1 parent e6da671 commit 88c6bf7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ jobs:
2424
VERSION="${VERSION#v}"
2525
echo "version=$VERSION" >> $GITHUB_OUTPUT
2626
27+
- name: Checkout main branch
28+
run: |
29+
# Validate we're releasing from main branch
30+
if [ "${{ github.event.release.target_commitish }}" != "main" ]; then
31+
echo "Error: Release was not created from 'main' branch (target_commitish=${{ github.event.release.target_commitish }})."
32+
exit 1
33+
fi
34+
# Checkout main branch (release event checks out the tag, putting us in detached HEAD)
35+
git checkout main
36+
git pull origin main
37+
2738
- name: Update version in files
2839
run: |
2940
VERSION="${{ steps.get_version.outputs.version }}"
@@ -39,12 +50,7 @@ jobs:
3950
git config user.email "github-actions[bot]@users.noreply.github.com"
4051
git add GNUmakefile README.md
4152
# Commit if there are changes (may not be if version files already match)
42-
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" || echo "No changes to commit"
43-
# Validate we're on main branch before pushing
44-
if [ "${{ github.event.release.target_commitish }}" != "main" ]; then
45-
echo "Error: Release was not created from 'main' branch (target_commitish=${{ github.event.release.target_commitish }})."
46-
exit 1
47-
fi
53+
git diff --staged --quiet || git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
4854
# Push to main
4955
git push origin main
5056

0 commit comments

Comments
 (0)