@@ -301,6 +301,37 @@ jobs:
301301 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
302302 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
303303
304+ gh_with_retry() {
305+ local output status attempt
306+ for attempt in 1 2 3 4 5 6; do
307+ set +e
308+ output="$(gh "$@" 2>&1)"
309+ status=$?
310+ set -e
311+ if [[ "$status" -eq 0 ]]; then
312+ printf '%s\n' "$output"
313+ return 0
314+ fi
315+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
316+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
317+ sleep $((attempt * 10))
318+ continue
319+ fi
320+ printf '%s\n' "$output" >&2
321+ return "$status"
322+ done
323+ printf '%s\n' "$output" >&2
324+ return "$status"
325+ }
326+
327+ fetch_child_run_json() {
328+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
329+ }
330+
331+ fetch_child_jobs() {
332+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
333+ }
334+
304335 cancel_child() {
305336 if [[ -n "${run_id:-}" ]]; then
306337 echo "Cancelling child workflow ${workflow}: ${run_id}" >&2
@@ -311,26 +342,26 @@ jobs:
311342
312343 poll_count=0
313344 while true; do
314- status="$(gh run view "$run_id" --json status --jq '.status')"
345+ status="$(fetch_child_run_json | jq -r '.status')"
315346 if [[ "$status" == "completed" ]]; then
316347 break
317348 fi
318349 poll_count=$((poll_count + 1))
319350 if (( poll_count % 10 == 0 )); then
320351 echo "Still waiting on ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
321- gh run view "$run_id" --json jobs -- jq '.jobs[] | select(.status != "completed") | {name, status, url}' || true
352+ fetch_child_jobs | jq 'select(.status != "completed") | {name, status, url: .html_url }' || true
322353 fi
323354 sleep 30
324355 done
325356 trap - EXIT INT TERM
326357
327- conclusion="$(gh run view "$run_id" --json conclusion --jq '.conclusion')"
328- url="$(gh run view "$run_id" --json url --jq '.url ')"
358+ conclusion="$(fetch_child_run_json | jq -r '.conclusion // "" ')"
359+ url="$(fetch_child_run_json | jq -r '.html_url ')"
329360 echo "${workflow} finished with ${conclusion}: ${url}"
330361 echo "url=${url}" >> "$GITHUB_OUTPUT"
331362 echo "conclusion=${conclusion}" >> "$GITHUB_OUTPUT"
332363 if [[ "$conclusion" != "success" ]]; then
333- gh run view "$run_id" --json jobs -- jq '.jobs[] | select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url}' || true
364+ fetch_child_jobs | jq 'select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url: .html_url }' || true
334365 exit 1
335366 fi
336367 }
@@ -401,6 +432,37 @@ jobs:
401432 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
402433 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
403434
435+ gh_with_retry() {
436+ local output status attempt
437+ for attempt in 1 2 3 4 5 6; do
438+ set +e
439+ output="$(gh "$@" 2>&1)"
440+ status=$?
441+ set -e
442+ if [[ "$status" -eq 0 ]]; then
443+ printf '%s\n' "$output"
444+ return 0
445+ fi
446+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
447+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
448+ sleep $((attempt * 10))
449+ continue
450+ fi
451+ printf '%s\n' "$output" >&2
452+ return "$status"
453+ done
454+ printf '%s\n' "$output" >&2
455+ return "$status"
456+ }
457+
458+ fetch_child_run_json() {
459+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
460+ }
461+
462+ fetch_child_jobs() {
463+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
464+ }
465+
404466 cancel_child() {
405467 if [[ -n "${run_id:-}" ]]; then
406468 echo "Cancelling child workflow ${workflow}: ${run_id}" >&2
@@ -411,26 +473,26 @@ jobs:
411473
412474 poll_count=0
413475 while true; do
414- status="$(gh run view "$run_id" --json status --jq '.status')"
476+ status="$(fetch_child_run_json | jq -r '.status')"
415477 if [[ "$status" == "completed" ]]; then
416478 break
417479 fi
418480 poll_count=$((poll_count + 1))
419481 if (( poll_count % 10 == 0 )); then
420482 echo "Still waiting on ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
421- gh run view "$run_id" --json jobs -- jq '.jobs[] | select(.status != "completed") | {name, status, url}' || true
483+ fetch_child_jobs | jq 'select(.status != "completed") | {name, status, url: .html_url }' || true
422484 fi
423485 sleep 30
424486 done
425487 trap - EXIT INT TERM
426488
427- conclusion="$(gh run view "$run_id" --json conclusion --jq '.conclusion')"
428- url="$(gh run view "$run_id" --json url --jq '.url ')"
489+ conclusion="$(fetch_child_run_json | jq -r '.conclusion // "" ')"
490+ url="$(fetch_child_run_json | jq -r '.html_url ')"
429491 echo "${workflow} finished with ${conclusion}: ${url}"
430492 echo "url=${url}" >> "$GITHUB_OUTPUT"
431493 echo "conclusion=${conclusion}" >> "$GITHUB_OUTPUT"
432494 if [[ "$conclusion" != "success" ]]; then
433- gh run view "$run_id" --json jobs -- jq '.jobs[] | select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url}' || true
495+ fetch_child_jobs | jq 'select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url: .html_url }' || true
434496 exit 1
435497 fi
436498 }
@@ -511,6 +573,37 @@ jobs:
511573 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
512574 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
513575
576+ gh_with_retry() {
577+ local output status attempt
578+ for attempt in 1 2 3 4 5 6; do
579+ set +e
580+ output="$(gh "$@" 2>&1)"
581+ status=$?
582+ set -e
583+ if [[ "$status" -eq 0 ]]; then
584+ printf '%s\n' "$output"
585+ return 0
586+ fi
587+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
588+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
589+ sleep $((attempt * 10))
590+ continue
591+ fi
592+ printf '%s\n' "$output" >&2
593+ return "$status"
594+ done
595+ printf '%s\n' "$output" >&2
596+ return "$status"
597+ }
598+
599+ fetch_child_run_json() {
600+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
601+ }
602+
603+ fetch_child_jobs() {
604+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
605+ }
606+
514607 release_check_blocking_job() {
515608 case "$1" in
516609 "resolve_target" | \
@@ -561,20 +654,25 @@ jobs:
561654
562655 poll_count=0
563656 while true; do
564- status="$(gh run view "$run_id" --json status --jq '.status')"
657+ status="$(fetch_child_run_json | jq -r '.status')"
565658 if [[ "$status" == "completed" ]]; then
566659 break
567660 fi
568661 poll_count=$((poll_count + 1))
569662 if (( poll_count % 10 == 0 )); then
570663 echo "Still waiting on ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
571- gh run view "$run_id" --json jobs -- jq '.jobs[] | select(.status != "completed") | {name, status, url}' || true
664+ fetch_child_jobs | jq 'select(.status != "completed") | {name, status, url: .html_url }' || true
572665 fi
573666 sleep 30
574667 done
575668 trap - EXIT INT TERM
576669
577- run_json="$(gh run view "$run_id" --json conclusion,url,jobs)"
670+ jobs_json="$(fetch_child_jobs | jq -s '{jobs: [.[] | {name, conclusion, url: .html_url}]}')"
671+ run_json="$(
672+ jq -s '.[0] + .[1]' \
673+ <(fetch_child_run_json | jq '{conclusion: (.conclusion // ""), url: .html_url}') \
674+ <(printf '%s\n' "$jobs_json")
675+ )"
578676 conclusion="$(jq -r '.conclusion' <<< "$run_json")"
579677 url="$(jq -r '.url' <<< "$run_json")"
580678 echo "${workflow} finished with ${conclusion}: ${url}"
@@ -787,6 +885,29 @@ jobs:
787885 echo "Dispatched npm-telegram-beta-e2e.yml: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
788886 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
789887
888+ gh_with_retry() {
889+ local output status attempt
890+ for attempt in 1 2 3 4 5 6; do
891+ set +e
892+ output="$(gh "$@" 2>&1)"
893+ status=$?
894+ set -e
895+ if [[ "$status" -eq 0 ]]; then
896+ printf '%s\n' "$output"
897+ return 0
898+ fi
899+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
900+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
901+ sleep $((attempt * 10))
902+ continue
903+ fi
904+ printf '%s\n' "$output" >&2
905+ return "$status"
906+ done
907+ printf '%s\n' "$output" >&2
908+ return "$status"
909+ }
910+
790911 cancel_child() {
791912 if [[ -n "${run_id:-}" ]]; then
792913 echo "Cancelling child workflow npm-telegram-beta-e2e.yml: ${run_id}" >&2
@@ -797,26 +918,26 @@ jobs:
797918
798919 poll_count=0
799920 while true; do
800- status="$(gh run view "$run_id" --json status --jq '.status')"
921+ status="$(gh_with_retry run view "$run_id" --json status --jq '.status')"
801922 if [[ "$status" == "completed" ]]; then
802923 break
803924 fi
804925 poll_count=$((poll_count + 1))
805926 if (( poll_count % 10 == 0 )); then
806927 echo "Still waiting on npm-telegram-beta-e2e.yml: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
807- gh run view "$run_id" --json jobs --jq '.jobs[] | select(.status != "completed") | {name, status, url}' || true
928+ gh_with_retry run view "$run_id" --json jobs --jq '.jobs[] | select(.status != "completed") | {name, status, url}' || true
808929 fi
809930 sleep 30
810931 done
811932 trap - EXIT INT TERM
812933
813- conclusion="$(gh run view "$run_id" --json conclusion --jq '.conclusion')"
814- url="$(gh run view "$run_id" --json url --jq '.url')"
934+ conclusion="$(gh_with_retry run view "$run_id" --json conclusion --jq '.conclusion')"
935+ url="$(gh_with_retry run view "$run_id" --json url --jq '.url')"
815936 echo "npm-telegram-beta-e2e.yml finished with ${conclusion}: ${url}"
816937 echo "url=${url}" >> "$GITHUB_OUTPUT"
817938 echo "conclusion=${conclusion}" >> "$GITHUB_OUTPUT"
818939 if [[ "$conclusion" != "success" ]]; then
819- gh run view "$run_id" --json jobs --jq '.jobs[] | select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url}' || true
940+ gh_with_retry run view "$run_id" --json jobs --jq '.jobs[] | select(.conclusion != "success" and .conclusion != "skipped") | {name, conclusion, url}' || true
820941 exit 1
821942 fi
822943
0 commit comments