Skip to content

Commit

Permalink
ci: rerun failed workflow runs automatically (#28473)
Browse files Browse the repository at this point in the history
* ci: rerun failed workflow runs automatically

* ci: remove unnecessary envs

* ci: write a script to workflows directly

* ci: add a info log

* ci: improve logs
  • Loading branch information
suzuki-shunsuke authored Nov 5, 2024
1 parent 28094e9 commit 12850dc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/auto-rerun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
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
d=$(date +%Y-%m-%d -d "4 day ago")
info "date: $d"
bot=app/aquaproj-aqua-registry
info "searching pull requests" >&2
shas=$(gh -R "$GITHUB_REPOSITORY" pr list \
-A "$bot" \
-S "created:>=$d" \
--json headRefOid \
-q '.[].headRefOid')
for sha in $shas; do
echo "searching workflow runs sha=$sha" >&2
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 runid=$runid" >&2
gh -R "$GITHUB_REPOSITORY" run rerun "$runid" --failed
done
done
env:
GITHUB_TOKEN: ${{github.token}}

0 comments on commit 12850dc

Please sign in to comment.