From fbc8d848f6d5e8e05f2b5d835fa5eb452108a3d2 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 24 Nov 2026 16:39:16 -0800 Subject: [PATCH] fix(ci): retry a failed job-status poll while http e2e jobs wait for the build --- .github/scripts/wait-for-e2e-build.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/scripts/wait-for-e2e-build.sh b/.github/scripts/wait-for-e2e-build.sh index eca34e0de94..8c7e4631deb 100755 --- a/.github/scripts/wait-for-e2e-build.sh +++ b/.github/scripts/wait-for-e2e-build.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash # Blocks until this run's `build (e2e)` job finishes, so an e2e job can check out, install and # migrate while the build runs instead of after it. Exits 0 only when that job succeeded; a failed, -# cancelled or skipped build, a missing or duplicated build job, or a failed API call exits non-zero. -# The job's own timeout bounds the wait. +# cancelled or skipped build, a missing or duplicated build job, or an API that keeps failing exits +# non-zero. A single failed poll (GitHub occasionally returns a truncated body) is retried on the next +# one. The job's own timeout bounds the wait. # # Usage: wait-for-e2e-build.sh (reads GITHUB_REPOSITORY and GITHUB_RUN_ID; needs `actions: read`) set -euo pipefail @@ -11,14 +12,26 @@ set -euo pipefail : "${GITHUB_RUN_ID:?}" poll_seconds=${E2E_BUILD_POLL_SECONDS:-10} +max_api_failures=3 +api_failures=0 started=$SECONDS while :; do # `filter=latest` lists each job's latest attempt, so re-running only a failed e2e job still sees # the build an earlier attempt finished. Called from ci.yml the name carries a `checks / ` prefix. - state=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" \ + if ! state=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" \ --jq '.jobs[] | select(.name == "build (e2e)" or (.name | endswith(" / build (e2e)"))) - | "\(.status) \(.conclusion // "")"') + | "\(.status) \(.conclusion // "")"'); then + api_failures=$((api_failures + 1)) + if [ "$api_failures" -ge "$max_api_failures" ]; then + echo "::error::Could not read this run's jobs $api_failures times in a row." + exit 1 + fi + echo "::warning::Could not read this run's jobs; trying again." + sleep "$poll_seconds" + continue + fi + api_failures=0 matches=$(printf '%s' "$state" | grep -c . || true) if [ "$matches" -ne 1 ]; then echo "::error::Expected one build (e2e) job in this run, found $matches."