Skip to content

Commit f0b5082

Browse files
authored
Fix release-tag workflow to push only annotated tags to main (#87)
* fix release-tag workflow for release tag on main The release-tag workflow checks out a commit (not a branch), leaving git in detached HEAD state. `git push origin HEAD` fails because git cannot resolve the bare `HEAD` symbolic ref to a remote branch name. Create a temporary local branch before committing and use an explicit refspec (`tmp/release-vX.Y.Z:refs/heads/main`) so the push is an unambiguous fast-forward to main. * fix(release-tag): push only the tag, not the commit to main Branch protection on main requires PRs, status checks, and code scanning — direct pushes are rejected. Instead of pushing the version-bump commit to main, commit it locally and push only the annotated tag ref. Downstream release jobs check out by tag so they receive the correct versioned code. * fix(release-tag): push only the tag, not the commit to main Branch protection on main requires PRs, status checks, and code scanning — direct pushes are rejected. Instead of pushing the version-bump commit to main, commit it locally and push only the annotated tag ref. Downstream release jobs check out by tag so they receive the correct versioned code.
1 parent ee8eeb7 commit f0b5082

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

.github/workflows/release-tag.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
144144
# workflow_call checkouts may leave us in detached HEAD when the
145145
# caller is triggered from a tag ref. Create a temporary local
146-
# branch so that `git commit` works and we can push to main.
146+
# branch so that `git commit` and `git tag` work correctly.
147147
TEMP_BRANCH="tmp/release-${TAG}"
148148
git checkout -B "${TEMP_BRANCH}"
149149
@@ -160,13 +160,16 @@ jobs:
160160
else
161161
git commit -m "Release ${TAG}: update versions to ${RELEASE_NAME}"
162162
CURRENT_SHA=$(git rev-parse HEAD)
163-
git push origin "${TEMP_BRANCH}:refs/heads/main"
164163
echo "✅ Committed version changes at ${CURRENT_SHA:0:8}"
165164
fi
166165
167-
# Create and push the tag
166+
# Create the annotated tag on the (possibly new) commit and push
167+
# it. We intentionally do NOT push the commit to main because
168+
# branch protection rules require PRs and status checks. The
169+
# tagged commit is reachable via the tag ref and is used by all
170+
# downstream release jobs to build artifacts.
168171
git tag -a "${TAG}" -m "Release ${TAG}" "${CURRENT_SHA}"
169-
git push origin "${TAG}"
172+
git push origin "refs/tags/${TAG}"
170173
echo "✅ Created and pushed tag ${TAG} at commit ${CURRENT_SHA:0:8}"
171174
echo "tag_sha=${CURRENT_SHA}" >> $GITHUB_OUTPUT
172175

0 commit comments

Comments
 (0)