Skip to content

Rerun failed workflow runs automatically #543

Rerun failed workflow runs automatically

Rerun failed workflow runs automatically #543

Workflow file for this run

---
name: Rerun failed workflow runs automatically
on:
workflow_dispatch: {}
schedule:
- cron: "0 */1 * * *" # Hourly
jobs:
rerun:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
actions: write # To rerun workflow runs
pull-requests: read # To list pull requests
steps:
- run: |
set -eu
info() {
echo "[INFO] $*" >&2
}
d=$(date +%Y-%m-%d -d "4 day ago")
info "date: $d"
bot=app/aquaproj-aqua-registry
info "searching pull requests"
shas=$(gh -R "$GITHUB_REPOSITORY" pr list \
-A "$bot" \
-S "created:>=$d -label:stop-rerun" \
--json headRefOid \
-q '.[].headRefOid')
for sha in $shas; do
info "searching workflow runs sha=$sha"
runids=$(gh -R "$GITHUB_REPOSITORY" run list \
-c "$sha" \
-s failure \
--json databaseId \
-q '.[].databaseId')
for runid in $runids; do
echo "[Rerunning a workflow run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$runid)" >> "$GITHUB_STEP_SUMMARY"
echo "::notice:: rerunning a workflow run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$runid" >&2
gh -R "$GITHUB_REPOSITORY" run rerun "$runid" --failed
done
done
env:
GITHUB_TOKEN: ${{github.token}}