Skip to content

Commit 15eb92f

Browse files
committed
refactor(ci): atomic release and tag creation using gh cli target
Made-with: Cursor
1 parent f3fde70 commit 15eb92f

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -819,41 +819,13 @@ jobs:
819819
subject-path: ${{ steps.attest-subjects.outputs.subjects }}
820820
sbom-path: sbom-spdx.json
821821

822-
- name: Create and push tag
823-
shell: bash
824-
run: |
825-
TAG="${{ needs.version.outputs.tag }}"
826-
SHA="${{ needs.version.outputs.sha }}"
827-
828-
git fetch --tags --force
829-
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "$TAG"; then
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"
849-
fi
850-
851-
- name: Create GitHub Release
822+
- name: Create Tag and GitHub Release
852823
shell: bash
853824
env:
854825
GH_TOKEN: ${{ github.token }}
855826
run: |
856827
TAG="${{ needs.version.outputs.tag }}"
828+
SHA="${{ needs.version.outputs.sha }}"
857829
RELEASE_NAME="Agibuild.Fulora $TAG"
858830
VERSION_SUFFIX="${{ needs.version.outputs.version_suffix }}"
859831
@@ -867,11 +839,14 @@ jobs:
867839
PRERELEASE_FLAG="--prerelease"
868840
fi
869841
842+
# The --target parameter instructs the GitHub API to create the tag
843+
# at the specified SHA if it doesn't already exist.
870844
gh release create "$TAG" \
845+
--target "$SHA" \
871846
--title "$RELEASE_NAME" \
872847
--generate-notes \
873848
$PRERELEASE_FLAG
874-
echo "Created release $TAG"
849+
echo "Created release and tag (if absent) $TAG at $SHA"
875850
876851
deploy-docs:
877852
name: Deploy Documentation

0 commit comments

Comments
 (0)