@@ -270,9 +270,31 @@ jobs:
270270 shift
271271
272272 local before_json dispatch_output run_id status conclusion url poll_count
273- before_json="$(gh run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
273+ gh_with_retry() {
274+ local output status attempt
275+ for attempt in 1 2 3 4 5 6; do
276+ set +e
277+ output="$(gh "$@" 2>&1)"
278+ status=$?
279+ set -e
280+ if [[ "$status" -eq 0 ]]; then
281+ printf '%s\n' "$output"
282+ return 0
283+ fi
284+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
285+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
286+ sleep $((attempt * 10))
287+ continue
288+ fi
289+ printf '%s\n' "$output" >&2
290+ return "$status"
291+ done
292+ printf '%s\n' "$output" >&2
293+ return "$status"
294+ }
295+ before_json="$(gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
274296
275- dispatch_output="$(gh workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@" 2>&1 )"
297+ dispatch_output="$(gh_with_retry workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@")"
276298 printf '%s\n' "$dispatch_output"
277299 run_id="$(
278300 printf '%s\n' "$dispatch_output" |
@@ -283,7 +305,7 @@ jobs:
283305 if [[ -z "$run_id" ]]; then
284306 for _ in $(seq 1 60); do
285307 run_id="$(
286- BEFORE_IDS="$before_json" gh run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
308+ BEFORE_IDS="$before_json" gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
287309 --jq 'map(select(.databaseId as $id | (env.BEFORE_IDS | fromjson | index($id) | not))) | sort_by(.createdAt) | reverse | .[0].databaseId // empty'
288310 )"
289311 if [[ -n "$run_id" ]]; then
@@ -301,29 +323,6 @@ jobs:
301323 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
302324 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
303325
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-
327326 fetch_child_run_json() {
328327 gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
329328 }
@@ -401,9 +400,31 @@ jobs:
401400 shift
402401
403402 local before_json dispatch_output run_id status conclusion url poll_count
404- before_json="$(gh run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
403+ gh_with_retry() {
404+ local output status attempt
405+ for attempt in 1 2 3 4 5 6; do
406+ set +e
407+ output="$(gh "$@" 2>&1)"
408+ status=$?
409+ set -e
410+ if [[ "$status" -eq 0 ]]; then
411+ printf '%s\n' "$output"
412+ return 0
413+ fi
414+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
415+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
416+ sleep $((attempt * 10))
417+ continue
418+ fi
419+ printf '%s\n' "$output" >&2
420+ return "$status"
421+ done
422+ printf '%s\n' "$output" >&2
423+ return "$status"
424+ }
425+ before_json="$(gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
405426
406- dispatch_output="$(gh workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@" 2>&1 )"
427+ dispatch_output="$(gh_with_retry workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@")"
407428 printf '%s\n' "$dispatch_output"
408429 run_id="$(
409430 printf '%s\n' "$dispatch_output" |
@@ -414,7 +435,7 @@ jobs:
414435 if [[ -z "$run_id" ]]; then
415436 for _ in $(seq 1 60); do
416437 run_id="$(
417- BEFORE_IDS="$before_json" gh run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
438+ BEFORE_IDS="$before_json" gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
418439 --jq 'map(select(.databaseId as $id | (env.BEFORE_IDS | fromjson | index($id) | not))) | sort_by(.createdAt) | reverse | .[0].databaseId // empty'
419440 )"
420441 if [[ -n "$run_id" ]]; then
@@ -432,29 +453,6 @@ jobs:
432453 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
433454 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
434455
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-
458456 fetch_child_run_json() {
459457 gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
460458 }
@@ -542,9 +540,31 @@ jobs:
542540 shift
543541
544542 local before_json dispatch_output run_id status conclusion url poll_count run_json
545- before_json="$(gh run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
543+ gh_with_retry() {
544+ local output status attempt
545+ for attempt in 1 2 3 4 5 6; do
546+ set +e
547+ output="$(gh "$@" 2>&1)"
548+ status=$?
549+ set -e
550+ if [[ "$status" -eq 0 ]]; then
551+ printf '%s\n' "$output"
552+ return 0
553+ fi
554+ if [[ "$output" == *"Bad credentials"* || "$output" == *"HTTP 401"* || "$output" == *"secondary rate limit"* || "$output" == *"API rate limit"* ]]; then
555+ echo "::warning::gh $* failed on attempt ${attempt}: ${output}" >&2
556+ sleep $((attempt * 10))
557+ continue
558+ fi
559+ printf '%s\n' "$output" >&2
560+ return "$status"
561+ done
562+ printf '%s\n' "$output" >&2
563+ return "$status"
564+ }
565+ before_json="$(gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 100 --json databaseId --jq '[.[].databaseId]')"
546566
547- dispatch_output="$(gh workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@" 2>&1 )"
567+ dispatch_output="$(gh_with_retry workflow run "$workflow" --ref "$CHILD_WORKFLOW_REF" "$@")"
548568 printf '%s\n' "$dispatch_output"
549569 run_id="$(
550570 printf '%s\n' "$dispatch_output" |
@@ -555,7 +575,7 @@ jobs:
555575 if [[ -z "$run_id" ]]; then
556576 for _ in $(seq 1 60); do
557577 run_id="$(
558- BEFORE_IDS="$before_json" gh run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
578+ BEFORE_IDS="$before_json" gh_with_retry run list --workflow "$workflow" --event workflow_dispatch --limit 50 --json databaseId,createdAt \
559579 --jq 'map(select(.databaseId as $id | (env.BEFORE_IDS | fromjson | index($id) | not))) | sort_by(.createdAt) | reverse | .[0].databaseId // empty'
560580 )"
561581 if [[ -n "$run_id" ]]; then
@@ -573,29 +593,6 @@ jobs:
573593 echo "Dispatched ${workflow}: https://github.com/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
574594 echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
575595
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-
599596 fetch_child_run_json() {
600597 gh_with_retry api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
601598 }
0 commit comments