Skip to content

Commit 94a04e1

Browse files
authored
ci(release): retry transient GitHub API suspension errors (#86859)
1 parent 8307e2f commit 94a04e1

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

‎.github/workflows/full-release-validation.yml‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ jobs:
287287
printf '%s\n' "$output"
288288
return 0
289289
fi
290-
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
290+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
291291
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
292292
sleep $((attempt * 10))
293293
continue
@@ -417,7 +417,7 @@ jobs:
417417
printf '%s\n' "$output"
418418
return 0
419419
fi
420-
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
420+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
421421
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
422422
sleep $((attempt * 10))
423423
continue
@@ -557,7 +557,7 @@ jobs:
557557
printf '%s\n' "$output"
558558
return 0
559559
fi
560-
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
560+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
561561
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
562562
sleep $((attempt * 10))
563563
continue
@@ -859,7 +859,7 @@ jobs:
859859
printf '%s\n' "$output"
860860
return 0
861861
fi
862-
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
862+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
863863
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
864864
sleep $((attempt * 10))
865865
continue
@@ -975,7 +975,7 @@ jobs:
975975
printf '%s\n' "$output"
976976
return 0
977977
fi
978-
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
978+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
979979
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
980980
sleep $((attempt * 10))
981981
continue
@@ -1089,6 +1089,29 @@ jobs:
10891089
run: |
10901090
set -euo pipefail
10911091
1092+
gh_with_retry() {
1093+
local output status attempt
1094+
for attempt in 1 2 3 4 5 6; do
1095+
set +e
1096+
output="$(gh "$@" 2>&1)"
1097+
status=$?
1098+
set -e
1099+
if [[ "$status" -eq 0 ]]; then
1100+
printf '%s\n' "$output"
1101+
return 0
1102+
fi
1103+
if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* || "$output" == *"Sorry. Your account was suspended"* ]]; then
1104+
echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
1105+
sleep $((attempt * 10))
1106+
continue
1107+
fi
1108+
printf '%s\n' "$output" >&2
1109+
return "$status"
1110+
done
1111+
printf '%s\n' "$output" >&2
1112+
return "$status"
1113+
}
1114+
10921115
release_check_blocking_job() {
10931116
case "$1" in
10941117
"resolve_target" | \
@@ -1145,7 +1168,7 @@ jobs:
11451168
fi
11461169
11471170
local run_json status conclusion url attempt head_sha
1148-
run_json="$(gh run view "$run_id" --json status,conclusion,url,attempt,headSha,jobs)"
1171+
run_json="$(gh_with_retry run view "$run_id" --json status,conclusion,url,attempt,headSha,jobs)"
11491172
status="$(jq -r '.status' <<< "$run_json")"
11501173
conclusion="$(jq -r '.conclusion' <<< "$run_json")"
11511174
url="$(jq -r '.url' <<< "$run_json")"
@@ -1192,7 +1215,7 @@ jobs:
11921215
fi
11931216
11941217
local run_json row
1195-
run_json="$(gh run view "$run_id" --json status,conclusion,url,createdAt,updatedAt,headSha)"
1218+
run_json="$(gh_with_retry run view "$run_id" --json status,conclusion,url,createdAt,updatedAt,headSha)"
11961219
row="$(
11971220
jq -r --arg label "$label" '
11981221
def ts: fromdateiso8601;
@@ -1228,7 +1251,7 @@ jobs:
12281251
echo
12291252
echo "### Slowest jobs: ${label}"
12301253
echo
1231-
gh run view "$run_id" --json jobs --jq '
1254+
gh_with_retry run view "$run_id" --json jobs --jq '
12321255
def ts: fromdateiso8601;
12331256
"| Job | Result | Minutes |",
12341257
"| --- | --- | ---: |",
@@ -1245,7 +1268,7 @@ jobs:
12451268
echo
12461269
echo "### Longest queues: ${label}"
12471270
echo
1248-
gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq ".jobs[] | @json" | jq -sr '
1271+
gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq ".jobs[] | @json" | jq -sr '
12491272
def ts: fromdateiso8601;
12501273
"| Job | Result | Queue minutes | Run minutes |",
12511274
"| --- | --- | ---: | ---: |",
@@ -1274,7 +1297,7 @@ jobs:
12741297
fi
12751298
12761299
local run_json status conclusion artifacts_json
1277-
run_json="$(gh run view "$run_id" --json status,conclusion,url,jobs)"
1300+
run_json="$(gh_with_retry run view "$run_id" --json status,conclusion,url,jobs)"
12781301
status="$(jq -r '.status' <<< "$run_json")"
12791302
conclusion="$(jq -r '.conclusion' <<< "$run_json")"
12801303
if [[ "$status" == "completed" && "$conclusion" == "success" ]]; then
@@ -1297,7 +1320,7 @@ jobs:
12971320
echo
12981321
echo "Artifacts:"
12991322
artifacts_json="$(
1300-
gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/artifacts?per_page=100" 2>/dev/null || true
1323+
gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/artifacts?per_page=100" 2>/dev/null || true
13011324
)"
13021325
if [[ -n "${artifacts_json// }" ]]; then
13031326
jq -r '

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ describe("package artifact reuse", () => {
984984
'check_child "release_checks" "$RELEASE_CHECKS_RUN_ID" 1 1',
985985
"gh run cancel",
986986
"NORMAL_CI_RESULT: ${{ needs.normal_ci.result }}",
987+
'Sorry. Your account was suspended',
988+
'gh_with_retry run view "$run_id" --json status,conclusion,url,attempt,headSha,jobs',
987989
]);
988990
expect(workflow).not.toContain("force-cancel");
989991
expect(workflow).not.toContain("workflow_ref:");
@@ -1095,7 +1097,7 @@ describe("package artifact reuse", () => {
10951097
expect(workflow).toContain("full-release-validation-${{ github.run_id }}");
10961098
expect(workflow).toContain("| Job | Result | Queue minutes | Run minutes |");
10971099
expect(workflow).toContain(
1098-
'gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100"',
1100+
'gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100"',
10991101
);
11001102
expect(workflow).toContain("(.started_at | ts) - (.created_at | ts)");
11011103
expect(workflow).not.toContain('gh run view "$run_id" --json createdAt,jobs');

0 commit comments

Comments
 (0)