From 928198cb673c8bbd6808adf71eaee6c308ded567 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Wed, 6 May 2026 12:28:45 -0400 Subject: [PATCH] Retry gh api on transient failures in classify-pr action GitHub's API occasionally returns a 5xx HTML error page, which causes gh api --jq to exit non-zero with a JSON parse error like 'invalid character \'<\' looking for beginning of value'. Add a short retry loop with exponential backoff (3 attempts, 2s/4s) so transient flakes don't flunk the run. --- .github/actions/classify-pr/action.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/actions/classify-pr/action.yml b/.github/actions/classify-pr/action.yml index 68d1eb3..7737256 100644 --- a/.github/actions/classify-pr/action.yml +++ b/.github/actions/classify-pr/action.yml @@ -53,7 +53,26 @@ runs: echo "triggers=true" >> "$GITHUB_OUTPUT" exit 0 fi - files=$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename') + # Retry the API call on transient failures. GitHub's API + # occasionally returns a 5xx HTML error page, which causes + # `gh api --jq` to exit non-zero with a JSON parse error like + # `invalid character '<' looking for beginning of value`. A + # short retry loop with backoff lets transient flakes recover + # without flunking the run. + attempt=1 + while :; do + if files=$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename'); then + break + fi + if [ "$attempt" -ge 3 ]; then + echo "classify-pr: gh api failed after 3 attempts" >&2 + exit 1 + fi + delay=$((2 ** attempt)) + echo "classify-pr: gh api attempt $attempt failed; retrying in ${delay}s..." >&2 + sleep "$delay" + attempt=$((attempt + 1)) + done if [ -z "$files" ]; then echo "No files reported for PR #${PR_NUMBER}; defaulting to triggers=true." echo "triggers=true" >> "$GITHUB_OUTPUT"