From a0a03a8f8f5dfb8e37d427305e881ec19c56ef8e Mon Sep 17 00:00:00 2001 From: objz Date: Sun, 26 Apr 2026 22:09:01 +0200 Subject: [PATCH] fix: tag-release re-tags when existing tag points to wrong commit Previously if a tag already existed (e.g. from a failed release), tag-release would skip because the version matched the latest tag. Now it detects stale tags pointing to the wrong SHA and re-creates them. --- .github/workflows/tag-release.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml index a019562..12e8f40 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/tag-release.yml @@ -54,19 +54,27 @@ jobs: | tail -n1 ) + tag="v${version}" + head_sha="$(git rev-parse HEAD)" + should_release=false if [[ -z "$latest" ]]; then should_release=true elif [[ "$version" != "$latest" && "$(printf '%s\n%s\n' "$latest" "$version" | sort -V | tail -n1)" == "$version" ]]; then should_release=true + elif git rev-parse "$tag" >/dev/null 2>&1; then + tag_sha="$(git rev-parse "$tag")" + if [[ "$tag_sha" != "$head_sha" ]]; then + echo "Tag ${tag} exists but points to ${tag_sha}, not HEAD ${head_sha}; will re-tag." + should_release=true + fi fi - tag="v${version}" echo "version=${version}" >> "$GITHUB_OUTPUT" echo "latest=${latest}" >> "$GITHUB_OUTPUT" echo "tag=${tag}" >> "$GITHUB_OUTPUT" echo "should-release=${should_release}" >> "$GITHUB_OUTPUT" - echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + echo "sha=${head_sha}" >> "$GITHUB_OUTPUT" if [[ "$should_release" == "true" ]]; then echo "Cargo.toml version ${version} is newer than latest tag ${latest:-}; creating ${tag}." @@ -88,7 +96,16 @@ jobs: exit 1 fi + remote_url="https://x-access-token:${RELEASE_TOKEN}@github.com/${{ github.repository }}.git" + git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + if git rev-parse "${TAG_NAME}" >/dev/null 2>&1; then + echo "Deleting existing tag ${TAG_NAME}" + git tag -d "${TAG_NAME}" + git push "$remote_url" ":refs/tags/${TAG_NAME}" + fi + git tag "${TAG_NAME}" - git push "https://x-access-token:${RELEASE_TOKEN}@github.com/${{ github.repository }}.git" "${TAG_NAME}" + git push "$remote_url" "${TAG_NAME}"