Skip to content

Commit 180a6de

Browse files
author
Selfeer
committed
Refactor GitHub Actions workflow to remove input for days back and streamline query for failed scheduled jobs
1 parent 658ba9a commit 180a6de

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

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

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ name: Re-run Failed Scheduled Jobs
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
days_back:
7-
description: 'Number of days to look back for failed jobs'
8-
required: true
9-
default: '7'
10-
type: string
115

126
jobs:
137
re-run-failed:
@@ -31,44 +25,41 @@ jobs:
3125
3226
- name: Find and re-run failed scheduled jobs
3327
run: |
34-
# Get the date range
35-
END_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
36-
START_DATE=$(date -u -d "${{ inputs.days_back }} days ago" +"%Y-%m-%dT%H:%M:%SZ")
37-
38-
# Get all workflow runs
39-
echo "Looking for failed scheduled jobs between $START_DATE and $END_DATE"
28+
echo "Looking for failed jobs from latest scheduled workflow runs"
4029
4130
# Get all workflow runs and filter for scheduled ones that failed
4231
gh api graphql -f query='
43-
query($owner: String!, $name: String!, $startDate: DateTime!, $endDate: DateTime!) {
32+
query GetFailedJobs($owner: String!, $name: String!) {
4433
repository(owner: $owner, name: $name) {
45-
workflowRuns(first: 100, filterBy: {created: {start: $startDate, end: $endDate}}) {
46-
nodes {
47-
id
48-
name
49-
event
50-
conclusion
51-
createdAt
52-
workflow {
53-
name
34+
actions {
35+
runs(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
36+
nodes {
5437
id
55-
}
56-
jobs(first: 100) {
57-
nodes {
58-
id
38+
name
39+
event
40+
conclusion
41+
createdAt
42+
workflow {
5943
name
60-
conclusion
61-
databaseId
44+
id
45+
}
46+
jobs(first: 100) {
47+
nodes {
48+
id
49+
name
50+
conclusion
51+
databaseId
52+
}
6253
}
6354
}
6455
}
6556
}
6657
}
67-
}' -f owner=${{ github.repository_owner }} -f name=${{ github.event.repository.name }} -f startDate=$START_DATE -f endDate=$END_DATE > runs.json
58+
}' -f owner=${{ github.repository_owner }} -f name=${{ github.event.repository.name }} > runs.json
6859
6960
# Process the results - get only the latest run for each workflow
7061
jq -r '
71-
.data.repository.workflowRuns.nodes
62+
.data.repository.actions.runs.nodes
7263
| map(select(.event == "schedule" and .conclusion == "failure"))
7364
| group_by(.workflow.id)
7465
| map(sort_by(.createdAt) | last)

0 commit comments

Comments
 (0)