Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit b813a93

Browse files
sapientpantsclaude
andauthored
fix: add retry logic to artifact search to handle race conditions (#317)
Added exponential backoff retry logic to the determine-artifact.sh script to handle race conditions where the Publish workflow starts before GitHub's API has indexed the completed Main workflow run. Changes: - Retry up to 5 times with increasing delays (5s, 10s, 15s, 20s, 25s) - Total retry window of ~75 seconds - Clear logging of retry attempts This fixes the issue where releases fail because: 1. Main workflow creates GitHub release 2. Release event triggers Publish workflow immediately 3. Publish workflow queries for Main workflow run 4. GitHub API hasn't yet indexed the just-completed workflow 5. Query returns empty results even though workflow succeeded 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 5c7e810 commit b813a93

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'sonarqube-mcp-server': patch
3+
---
4+
5+
Fix race condition in artifact determination script
6+
7+
- Add retry logic with exponential backoff to determine-artifact.sh
8+
- Wait up to 5 attempts with increasing delays (5s, 10s, 15s, 20s, 25s)
9+
- Fixes race condition where Publish workflow starts before Main workflow is indexed by GitHub API
10+
- Total retry window: ~75 seconds, giving GitHub's API time to index completed workflow runs

.github/scripts/determine-artifact.sh

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,44 @@ PARENT_SHA=$(echo "$PARENT_BODY" | jq -r '.parents[0].sha')
115115
echo "📌 Parent commit (build trigger): $PARENT_SHA"
116116

117117
# Find the workflow run that created the release artifacts
118+
# Retry with exponential backoff to handle race conditions
118119
RUNS_API_URL="https://api.github.com/repos/$REPO/actions/runs?head_sha=$PARENT_SHA&status=success&event=push"
119120
echo "🔍 Searching for successful workflow runs for parent commit $PARENT_SHA"
120121

121-
RUNS_RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -w "\n%{http_code}" $RUNS_API_URL)
122-
RUNS_BODY=$(echo "$RUNS_RESPONSE" | head -n -1)
123-
RUNS_STATUS=$(echo "$RUNS_RESPONSE" | tail -n 1)
122+
MAX_RETRIES=5
123+
RETRY_COUNT=0
124+
MAIN_RUN=""
124125

125-
if [ "$RUNS_STATUS" != "200" ]; then
126-
echo "❌ Failed to fetch workflow runs with status $RUNS_STATUS"
127-
echo "Response: $RUNS_BODY"
128-
exit 1
129-
fi
126+
while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ -z "$MAIN_RUN" ]; do
127+
if [ $RETRY_COUNT -gt 0 ]; then
128+
WAIT_TIME=$((5 * RETRY_COUNT))
129+
echo "⏳ Waiting ${WAIT_TIME}s before retry $RETRY_COUNT/$MAX_RETRIES..."
130+
sleep $WAIT_TIME
131+
fi
132+
133+
RUNS_RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -w "\n%{http_code}" $RUNS_API_URL)
134+
RUNS_BODY=$(echo "$RUNS_RESPONSE" | head -n -1)
135+
RUNS_STATUS=$(echo "$RUNS_RESPONSE" | tail -n 1)
136+
137+
if [ "$RUNS_STATUS" != "200" ]; then
138+
echo "❌ Failed to fetch workflow runs with status $RUNS_STATUS"
139+
echo "Response: $RUNS_BODY"
140+
exit 1
141+
fi
142+
143+
# Find the Main workflow run
144+
MAIN_RUN=$(echo "$RUNS_BODY" | jq -r '.workflow_runs[] | select(.name == "Main") | {id: .id, created_at: .created_at}')
130145

131-
# Find the Main workflow run
132-
MAIN_RUN=$(echo "$RUNS_BODY" | jq -r '.workflow_runs[] | select(.name == "Main") | {id: .id, created_at: .created_at}')
146+
if [ -z "$MAIN_RUN" ]; then
147+
RETRY_COUNT=$((RETRY_COUNT + 1))
148+
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
149+
echo "⚠️ Main workflow not found yet (attempt $RETRY_COUNT/$MAX_RETRIES)"
150+
fi
151+
fi
152+
done
133153

134154
if [ -z "$MAIN_RUN" ]; then
135-
echo "❌ No successful Main workflow run found for parent commit $PARENT_SHA"
155+
echo "❌ No successful Main workflow run found for parent commit $PARENT_SHA after $MAX_RETRIES attempts"
136156
echo "Available runs:"
137157
echo "$RUNS_BODY" | jq -r '.workflow_runs[] | "\(.name): \(.id) (\(.status))"'
138158
exit 1

0 commit comments

Comments
 (0)