File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -27,14 +27,28 @@ jobs:
2727 run : |
2828 echo "Looking for failed jobs from latest scheduled workflow runs"
2929
30- # Get all workflow runs and filter for scheduled ones that failed
31- gh api -X GET "/repos/${{ github.repository }}/actions/runs?event=schedule&status=failure& per_page=100" > runs.json
30+ # Get all workflow runs (not filtered by status to see latest of each)
31+ gh api -X GET "/repos/${{ github.repository }}/actions/runs?per_page=100" > runs.json
3232
33- # Process the results - get only the latest run for each workflow
34- jq -r '
33+ # Calculate the cutoff date (30 days ago)
34+ CUTOFF_DATE=$(date -u -d "30 days ago" +"%Y-%m-%dT%H:%M:%SZ")
35+
36+ # Process the results - get only the latest scheduled run for each workflow
37+ jq -r --arg cutoff "$CUTOFF_DATE" '
3538 .workflow_runs
3639 | group_by(.workflow_id)
37- | map(sort_by(.created_at) | last)
40+ | map(
41+ sort_by(.created_at)
42+ | reverse
43+ | map(select(.event == "schedule"))
44+ | first
45+ | select(
46+ . != null and
47+ .status == "completed" and
48+ .conclusion == "failure" and
49+ .created_at >= $cutoff
50+ )
51+ )
3852 | .[]
3953 | .jobs_url
4054 | @text
4862 | @tsv
4963 ' jobs.json | while IFS=$'\t' read -r job_id job_name; do
5064 echo "Re-running failed job: $job_name (ID: $job_id)"
51- gh api -X POST "/repos/${{ github.repository }}/actions/jobs/$job_id/rerun"
65+ gh api -X POST "/repos/${{ github.repository }}/actions/jobs/$job_id/rerun" || {
66+ echo "Failed to re-run job $job_name (ID: $job_id)"
67+ }
5268 echo "Successfully triggered re-run for $job_name"
5369 done
5470 done
You can’t perform that action at this time.
0 commit comments