ci: Add error handling and retry logic to release upload
Some checks failed
Build and Release / Lint (push) Successful in 3m6s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 1m3s
Build and Release / Unit Tests (push) Failing after 3m25s
Build and Release / Build Binaries (amd64, darwin) (push) Failing after 56s
Build and Release / Build Binaries (amd64, linux) (push) Failing after 1m1s
Build and Release / Build Binaries (amd64, windows) (push) Failing after 57s
Build and Release / Build Binaries (arm64, darwin) (push) Failing after 55s
Build and Release / Build Binaries (arm64, linux) (push) Failing after 53s

- Add set -e for fail-fast
- Add retry loop for release creation (handles race conditions)
- Show upload success/failure with clear messages
- Exit with error if upload fails

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
David H. Friedel Jr. 2026-01-10 06:05:36 -05:00
parent e0ba7c9c00
commit ab3cf76297

View File

@ -222,46 +222,61 @@ jobs:
- name: Upload to release
if: startsWith(github.ref, 'refs/tags/v')
run: |
set -e
VERSION=$(git describe --tags --always 2>/dev/null || echo "dev")
echo "Uploading binaries for $VERSION"
# Get or create release
# Get or create release (with retry for race conditions)
TAG="${{ github.ref_name }}"
EXISTING=$(curl -s \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG")
if echo "$EXISTING" | grep -q '"id":[0-9]'; then
RELEASE_ID=$(echo "$EXISTING" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
echo "Found existing release: $RELEASE_ID"
else
echo "Creating release..."
RESPONSE=$(curl -s -X POST \
for i in 1 2 3; do
EXISTING=$(curl -sf \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"tag_name":"'"$TAG"'","name":"GitCaddy '"$TAG"'","body":"Official release.","draft":false,"prerelease":false}' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
echo "Created release: $RELEASE_ID"
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG" 2>/dev/null || echo "")
if echo "$EXISTING" | grep -q '"id":[0-9]'; then
RELEASE_ID=$(echo "$EXISTING" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
echo "Found existing release: $RELEASE_ID"
break
else
echo "Attempt $i: Creating release..."
RESPONSE=$(curl -sf -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"tag_name":"'"$TAG"'","name":"GitCaddy '"$TAG"'","body":"Official release.","draft":false,"prerelease":false}' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" 2>&1 || echo "")
if echo "$RESPONSE" | grep -q '"id":[0-9]'; then
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
echo "Created release: $RELEASE_ID"
break
fi
echo "Failed to create, retrying in 5s..."
sleep 5
fi
done
if [ -z "$RELEASE_ID" ]; then
echo "ERROR: Could not get or create release"
exit 1
fi
# Upload files
for file in dist/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
# Delete existing asset if present
ASSETS=$(curl -s -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID")
ASSET_ID=$(echo "$ASSETS" | grep -o "\"id\":[0-9]*,\"name\":\"$filename\"" | grep -o '"id":[0-9]*' | cut -d: -f2)
if [ -n "$ASSET_ID" ]; then
echo "Deleting existing $filename"
curl -s -X DELETE -H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets/$ASSET_ID"
fi
echo "Uploading $filename..."
curl -s -X POST \
UPLOAD_RESPONSE=$(curl -sf -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-F "attachment=@$file" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$filename"
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$filename" 2>&1)
if echo "$UPLOAD_RESPONSE" | grep -q '"id":[0-9]'; then
echo "✓ Uploaded $filename successfully"
else
echo "✗ Failed to upload $filename: $UPLOAD_RESPONSE"
exit 1
fi
fi
done
echo "All uploads complete!"