@@ -28,22 +28,79 @@ jobs:
2828
2929 - name : Delete existing release (if re-running)
3030 run : |
31- # Check if release exists and delete it to allow re-upload
32- RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
33- "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}" \
34- | jq -r '.id // empty')
31+ set -e
3532
36- if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "null" ]; then
37- echo "Release ${{ github.ref_name }} exists (ID: $RELEASE_ID), deleting to allow re-upload..."
38- curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
39- "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" || true
40- echo "Release deleted successfully"
33+ echo "Checking for existing release: ${{ github.ref_name }}"
34+
35+ # Check if release exists and get release ID
36+ RESPONSE=$(curl -s -w "\n%{http_code}" -H "Authorization: token $GITHUB_TOKEN" \
37+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}")
38+
39+ HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
40+ BODY=$(echo "$RESPONSE" | sed '$d')
41+
42+ echo "API Response HTTP Code: $HTTP_CODE"
43+
44+ if [ "$HTTP_CODE" = "200" ]; then
45+ RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty')
46+ echo "Found release ID: $RELEASE_ID"
47+
48+ if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "null" ]; then
49+ echo "Deleting release ${{ github.ref_name }} (ID: $RELEASE_ID) to allow re-upload..."
50+
51+ DELETE_RESPONSE=$(curl -s -w "\n%{http_code}" -X DELETE \
52+ -H "Authorization: token $GITHUB_TOKEN" \
53+ "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID")
54+
55+ DELETE_HTTP_CODE=$(echo "$DELETE_RESPONSE" | tail -n1)
56+ DELETE_BODY=$(echo "$DELETE_RESPONSE" | sed '$d')
57+
58+ echo "Delete API Response HTTP Code: $DELETE_HTTP_CODE"
59+
60+ if [ "$DELETE_HTTP_CODE" = "204" ]; then
61+ echo "✅ Release deleted successfully"
62+ else
63+ echo "❌ Failed to delete release. HTTP Code: $DELETE_HTTP_CODE"
64+ echo "Response: $DELETE_BODY"
65+ exit 1
66+ fi
67+ else
68+ echo "⚠️ Could not extract release ID from response"
69+ echo "Response body: $BODY"
70+ exit 1
71+ fi
72+ elif [ "$HTTP_CODE" = "404" ]; then
73+ echo "✅ No existing release found for ${{ github.ref_name }} (this is expected for new releases)"
74+ else
75+ echo "⚠️ Unexpected HTTP code when checking for release: $HTTP_CODE"
76+ echo "Response: $BODY"
77+ # Don't fail for unexpected codes, might be a temporary API issue
78+ echo "Continuing anyway..."
79+ fi
80+ env :
81+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82+
83+ - name : Verify release was deleted
84+ run : |
85+ echo "Verifying release ${{ github.ref_name }} was deleted..."
86+
87+ VERIFY_RESPONSE=$(curl -s -w "\n%{http_code}" -H "Authorization: token $GITHUB_TOKEN" \
88+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}")
89+
90+ VERIFY_HTTP_CODE=$(echo "$VERIFY_RESPONSE" | tail -n1)
91+
92+ if [ "$VERIFY_HTTP_CODE" = "404" ]; then
93+ echo "✅ Verification passed: Release does not exist (ready for GoReleaser)"
94+ elif [ "$VERIFY_HTTP_CODE" = "200" ]; then
95+ echo "❌ Verification failed: Release still exists!"
96+ echo "This should not happen. The deletion step may have failed."
97+ exit 1
4198 else
42- echo "No existing release found for ${{ github.ref_name }}"
99+ echo "⚠️ Unexpected HTTP code during verification: $VERIFY_HTTP_CODE"
100+ echo "Proceeding anyway, but this may cause issues..."
43101 fi
44102 env :
45103 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46- continue-on-error : true
47104
48105 - name : Run GoReleaser
49106 uses : goreleaser/goreleaser-action@v5
0 commit comments