



















@@ -301,12 +301,35 @@ jobs:
301301 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
302302 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
303303304+ 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+304327 fetch_child_run_json() {
305- gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
328+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
306329 }
307330308331 fetch_child_jobs() {
309- gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
332+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
310333 }
311334312335 cancel_child() {
@@ -409,12 +432,35 @@ jobs:
409432 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
410433 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
411434435+ 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+412458 fetch_child_run_json() {
413- gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
459+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
414460 }
415461416462 fetch_child_jobs() {
417- gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
463+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
418464 }
419465420466 cancel_child() {
@@ -527,12 +573,35 @@ jobs:
527573 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
528574 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
529575576+ 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+530599 fetch_child_run_json() {
531- gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
600+ gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
532601 }
533602534603 fetch_child_jobs() {
535- gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
604+ gh_with_retry api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100" --jq '.jobs[]'
536605 }
537606538607 release_check_blocking_job() {
@@ -816,6 +885,29 @@ jobs:
816885 echo "Dispatched npm-telegram-beta-e2e.yml: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
817886 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
818887888+ 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+819911 cancel_child() {
820912 if [[ -n "${run_id:-}" ]]; then
821913 echo "Cancelling child workflow npm-telegram-beta-e2e.yml: ${run_id}" >&2
@@ -826,26 +918,26 @@ jobs:
826918827919 poll_count=0
828920 while true; do
829- status="$(gh run view "$run_id" --json status --jq '.status')"
921+ status="$(gh_with_retry run view "$run_id" --json status --jq '.status')"
830922 if [[ "$status" == "completed" ]]; then
831923 break
832924 fi
833925 poll_count=$((poll_count + 1))
834926 if (( poll_count % 10 == 0 )); then
835927 echo "Still waiting on npm-telegram-beta-e2e.yml: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
836- 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
837929 fi
838930 sleep 30
839931 done
840932 trap - EXIT INT TERM
841933842- conclusion="$(gh run view "$run_id" --json conclusion --jq '.conclusion')"
843- 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')"
844936 echo "npm-telegram-beta-e2e.yml finished with ${conclusion}: ${url}"
845937 echo "url=${url}" >> "$GITHUB_OUTPUT"
846938 echo "conclusion=${conclusion}" >> "$GITHUB_OUTPUT"
847939 if [[ "$conclusion" != "success" ]]; then
848- 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
849941 exit 1
850942 fi
851943此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。