Skip to content

Instantly share code, notes, and snippets.

@findepi
Last active June 14, 2024 12:50
Show Gist options
  • Save findepi/8c44f59d04502cd5d6735590e36abf98 to your computer and use it in GitHub Desktop.
Save findepi/8c44f59d04502cd5d6735590e36abf98 to your computer and use it in GitHub Desktop.
Tirelessly rerun all the failed checks in all open PRs
#bash
set -euo pipefail
sleep_before_reruns_seconds=$[10 * 60]
while true; do
slept=false
for pr_link in $(gh pr list --search 'author:@me' --limit 999 --json 'url' --jq '.[].url'); do
echo "checking PR ${pr_link}"
found_failures=false
for run_id in $(gh pr checks "${pr_link}" --json 'link,state' --jq 'map(. | select(.state == "FAILURE") | .link | sub(".*/runs/(?<id>[0-9]+)/job/[0-9]+$"; "\(.id)") ) | unique | .[]'); do
found_failures=true
echo "found run with failed jobs: ${run_id}, will re-run"
gh run rerun --failed "${run_id}"
done
if "${found_failures}"; then
echo "We have re-run something. To avoid stressing resources, let's take a nap (${sleep_before_reruns_seconds}s)"
sleep "${sleep_before_reruns_seconds}"
slept=true
fi
done
if ! "${slept}"; then
echo "we have looped through all PRs, without rerunning anything, and without sleeping. To avoid stressing github, let's take a nap (${sleep_before_reruns_seconds}s)"
sleep "${sleep_before_reruns_seconds}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment