@@ -29,28 +29,41 @@ jobs:
2929 env :
3030 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3131 COMMIT_SHA : ${{ github.event.pull_request.head.sha }}
32- github_repository : ${{ github.repository }}
32+ GITHUB_REPOSITORY : ${{ github.repository }}
3333 run : |
34+ # Exit on error, undefined variables, or pipe failures
35+ set -euo pipefail
36+
3437 echo "Waiting for CircleCI check suite to complete..."
35- end=$((SECONDS+1800))
38+ # Timeout after 30 minutes (1800 seconds)
39+ end=$((SECONDS + 1800))
40+
3641 while [ $SECONDS -lt $end ]; do
37- suite_json=$(gh api "repos/${github_repository}/commits/${COMMIT_SHA}/check-suites" --jq '.check_suites[] | select(.app.slug=="circleci-checks")')
42+ # Query GitHub API for check suites associated with this commit
43+ # || echo "" allows retry on transient API failures instead of exiting
44+ suite_json=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${COMMIT_SHA}/check-suites" \
45+ --jq '.check_suites[] | select(.app.slug == "circleci-checks")' || echo "")
46+
3847 if [ -z "$suite_json" ]; then
3948 echo "CircleCI check suite not found yet, retrying..."
4049 else
4150 status=$(echo "$suite_json" | jq -r '.status')
4251 conclusion=$(echo "$suite_json" | jq -r '.conclusion // empty')
43- echo "Current CircleCI check suite status: $status (conclusion: $conclusion)"
52+ echo "CircleCI status: $status, conclusion: $conclusion"
53+
54+ # Check suite is done when status is "completed" AND conclusion is set
4455 if [ "$status" = "completed" ] && [ -n "$conclusion" ]; then
45- break
56+ echo "Check suite completed successfully"
57+ exit 0
4658 fi
4759 fi
60+
61+ # Poll every 20 seconds
4862 sleep 20
4963 done
50- if [ $SECONDS -ge $end ]; then
51- echo "Timed out waiting for CircleCI check suite."
52- exit 1
53- fi
64+
65+ echo "ERROR : Timed out waiting for CircleCI check suite"
66+ exit 1
5467
5568 - name : Get CircleCI run's artifacts and upload them to Hub
5669 id : circleci
0 commit comments