Skip to content

Instantly share code, notes, and snippets.

@creachadair
Last active May 10, 2022 15:40
Show Gist options
  • Save creachadair/e5127066073ff8b03fbdb977eb404ef4 to your computer and use it in GitHub Desktop.
Save creachadair/e5127066073ff8b03fbdb977eb404ef4 to your computer and use it in GitHub Desktop.
A script to retry a failed GitHub actions run.
#!/bin/zsh
set -euo pipefail
readonly pollsec=5
if [[ "$#" = 0 ]] ; then
echo "Missing required run ID" 1>&2
exit 2
fi
runjob() {
local id="${1:?missing ID}"
while ! gh run watch -i "$pollsec" --exit-status "$id" ; do
voicenote Run failed, retrying.
sleep 1
gh run rerun --failed "$id"
sleep 1
done
voicenote Run finished successfully.
}
trap 'wait' EXIT
for id in "$@" ; do
runjob "$id" &
done
echo "Waiting for $# jobs to complete..." 1>&2
#!/bin/bash
set -euo pipefail
readonly here="$(dirname $0)"
readonly match='(Test|e2e)'
readonly branch="${1:?missing branch name}"
gh run list --limit=200 --json conclusion,name,databaseId,status,headBranch \
| jq '
.[]
| select(.headBranch=="'"${branch}"'")
| [ select(.name=="e2e")
| select(.conclusion=="" or .conclusion=="failure")][:1] +
[ select(.name=="Test")
| select(.conclusion=="" or .conclusion=="failure")][:1]
| .[] | .databaseId' \
| xargs -t "${here}"/gh-run.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment