fix: create-tag tolerates existing tags instead of failing the workflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-03 23:12:30 +02:00
parent 038a8db16f
commit 5c4a892e7b

View File

@@ -123,15 +123,24 @@ spec:
TAG="${PREFIX}.${NEXT_N}"
echo "Creating tag: ${TAG} at ${SHA}"
# Create the tag
RESULT=$(curl -sf -X POST \
# Create the tag (tolerate failure if tag already exists)
HTTP_CODE=$(curl -s -o /tmp/tag_response -w "%{http_code}" -X POST \
-H "PRIVATE-TOKEN: ${GITLAB_PAT}" \
-d "tag_name=${TAG}" \
-d "ref=${SHA}" \
"${GITLAB}/api/v4/projects/${PROJECT_ID}/repository/tags")
echo "$RESULT" | grep -q "$TAG" || { echo "Tag creation failed: $RESULT"; exit 1; }
echo "Tag ${TAG} created successfully"
RESULT=$(cat /tmp/tag_response 2>/dev/null || echo "{}")
if [ "$HTTP_CODE" = "201" ]; then
echo "Tag ${TAG} created successfully"
elif [ "$HTTP_CODE" = "400" ] && echo "$RESULT" | grep -q "already exists"; then
echo "Tag ${TAG} already exists — reusing"
else
echo "WARN: Tag creation returned HTTP ${HTTP_CODE}: ${RESULT}"
echo "Falling back to dev tag"
TAG="dev-$(echo $SHA | cut -c1-8)"
fi
mkdir -p /tmp/outputs
echo -n "$TAG" > /tmp/outputs/tag