Skip to content

Commit 658ba9a

Browse files
author
Selfeer
committed
Enhance GitHub Actions workflow to process only the latest failed scheduled jobs for re-running
1 parent 18d560d commit 658ba9a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

.github/workflows/re-run-scheduled-fails.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ jobs:
4848
name
4949
event
5050
conclusion
51+
createdAt
5152
workflow {
5253
name
54+
id
5355
}
5456
jobs(first: 100) {
5557
nodes {
@@ -64,8 +66,18 @@ jobs:
6466
}
6567
}' -f owner=${{ github.repository_owner }} -f name=${{ github.event.repository.name }} -f startDate=$START_DATE -f endDate=$END_DATE > runs.json
6668
67-
# Process the results
68-
jq -r '.data.repository.workflowRuns.nodes[] | select(.event == "schedule") | select(.conclusion == "failure") | .jobs.nodes[] | select(.conclusion == "failure") | [.databaseId, .name] | @tsv' runs.json | while IFS=$'\t' read -r job_id job_name; do
69+
# Process the results - get only the latest run for each workflow
70+
jq -r '
71+
.data.repository.workflowRuns.nodes
72+
| map(select(.event == "schedule" and .conclusion == "failure"))
73+
| group_by(.workflow.id)
74+
| map(sort_by(.createdAt) | last)
75+
| .[]
76+
| .jobs.nodes[]
77+
| select(.conclusion == "failure")
78+
| [.databaseId, .name]
79+
| @tsv
80+
' runs.json | while IFS=$'\t' read -r job_id job_name; do
6981
echo "Re-running failed job: $job_name (ID: $job_id)"
7082
gh api -X POST /repos/${{ github.repository }}/actions/jobs/$job_id/rerun
7183
echo "Successfully triggered re-run for $job_name"

0 commit comments

Comments
 (0)