Skip to content

Commit f3fde70

Browse files
committed
fix(ci): make release creation and tag pushing idempotent
Made-with: Cursor
1 parent 2dfed48 commit f3fde70

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -826,31 +826,40 @@ jobs:
826826
SHA="${{ needs.version.outputs.sha }}"
827827
828828
git fetch --tags --force
829-
if git rev-parse "$TAG" >/dev/null 2>&1; then
830-
echo "::error::Tag $TAG already exists locally"
831-
exit 1
832-
fi
833829
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "$TAG"; then
834-
echo "::error::Tag $TAG already exists on remote"
835-
exit 1
830+
REMOTE_SHA=$(git ls-remote --tags origin "refs/tags/$TAG^{}" | awk '{print $1}')
831+
if [ -z "$REMOTE_SHA" ]; then
832+
REMOTE_SHA=$(git ls-remote --tags origin "refs/tags/$TAG" | awk '{print $1}')
833+
fi
834+
835+
if [ "$REMOTE_SHA" == "$SHA" ]; then
836+
echo "Tag $TAG already exists and points to current SHA. Skipping tag push."
837+
else
838+
echo "::error::Tag $TAG already exists on remote but points to a different SHA ($REMOTE_SHA != $SHA)"
839+
exit 1
840+
fi
841+
else
842+
if git rev-parse "$TAG" >/dev/null 2>&1; then
843+
echo "::error::Tag $TAG already exists locally but not on remote"
844+
exit 1
845+
fi
846+
git tag "$TAG" "$SHA"
847+
git push origin "$TAG"
848+
echo "Created and pushed tag $TAG at $SHA"
836849
fi
837850
838-
git tag "$TAG" "$SHA"
839-
git push origin "$TAG"
840-
echo "Created and pushed tag $TAG at $SHA"
841-
842851
- name: Create GitHub Release
843852
shell: bash
844853
env:
845-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
854+
GH_TOKEN: ${{ github.token }}
846855
run: |
847856
TAG="${{ needs.version.outputs.tag }}"
848857
RELEASE_NAME="Agibuild.Fulora $TAG"
849858
VERSION_SUFFIX="${{ needs.version.outputs.version_suffix }}"
850859
851860
if gh release view "$TAG" >/dev/null 2>&1; then
852-
echo "::error::Release already exists for tag $TAG"
853-
exit 1
861+
echo "Release for tag $TAG already exists. Assuming success."
862+
exit 0
854863
fi
855864
856865
PRERELEASE_FLAG=""

0 commit comments

Comments
 (0)