Skip to content

Commit 440a136

Browse files
committed
ci(workflows): fixed release workflow git operations for tag handling
- Dynamically determine target branch (main or master) to ensure pushes reach the correct branch. - Move git tag to the versioned commit so GoReleaser builds from the correct release artifact. - Restore branch context before pushing version bump to prevent tag checkout state issues.
1 parent 92c076e commit 440a136

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/go-release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ jobs:
4747
git config user.email "github-actions[bot]@users.noreply.github.com"
4848
git add version.go
4949
git commit -m "chore: set version to ${{ env.RELEASE_VERSION }} for release"
50-
git push
50+
# Find the branch that contains this tag and push to it
51+
BRANCH=$(git branch -r --contains HEAD | grep -E 'origin/(main|master)$' | head -1 | sed 's/origin\///' || echo "main")
52+
git push origin HEAD:${BRANCH}
53+
# Move the tag to the new commit so GoReleaser builds from the versioned commit
54+
TAG=${GITHUB_REF#refs/tags/}
55+
git tag -fa "$TAG" -m "Release $TAG"
56+
git push origin "$TAG" --force
5157
5258
- name: Run GoReleaser
5359
uses: goreleaser/goreleaser-action@v6
@@ -84,6 +90,10 @@ jobs:
8490
run: |
8591
git config user.name "github-actions[bot]"
8692
git config user.email "github-actions[bot]@users.noreply.github.com"
93+
# Switch back to the branch (we were on the tag)
94+
BRANCH=$(git branch -r --contains HEAD | grep -E 'origin/(main|master)$' | head -1 | sed 's/origin\///' || echo "main")
95+
git checkout ${BRANCH}
96+
git pull origin ${BRANCH} --rebase || true
8797
git add version.go
8898
git commit -m "chore: bump to next dev version"
89-
git push
99+
git push origin ${BRANCH}

0 commit comments

Comments
 (0)