WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f1b4766

Browse files
committed
Add automatic retry for failed test jobs
1 parent e070759 commit f1b4766

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests auto-rerun
2+
3+
on:
4+
workflow_run:
5+
workflows: [ "Tests" ]
6+
types: [ completed ]
7+
8+
jobs:
9+
rerun-failed-matrix-jobs-once:
10+
if: >
11+
${{
12+
github.event.workflow_run.conclusion == 'failure' &&
13+
github.event.workflow_run.run_attempt == 1
14+
}}
15+
runs-on: ubuntu-24.04
16+
17+
permissions:
18+
actions: write
19+
contents: read
20+
21+
steps:
22+
- name: Decide whether to rerun (only if matrix jobs failed)
23+
env:
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
REPO: ${{ github.repository }}
26+
RUN_ID: ${{ github.event.workflow_run.id }}
27+
run: |
28+
echo "Inspecting jobs of workflow run $RUN_ID in $REPO"
29+
30+
jobs_json="$(gh api repos/$REPO/actions/runs/$RUN_ID/jobs)"
31+
32+
echo "Jobs and conclusions:"
33+
echo "$jobs_json" | jq '.jobs[] | {name: .name, conclusion: .conclusion}'
34+
35+
failed_matrix_jobs=$(echo "$jobs_json" | jq '
36+
[ .jobs[]
37+
| select(.conclusion == "failure"
38+
and (.name | startswith("Integration Tests (")))
39+
]
40+
| length
41+
')
42+
43+
echo "Failed Integration Tests matrix jobs: $failed_matrix_jobs"
44+
45+
if [ "$failed_matrix_jobs" -gt 0 ]; then
46+
echo "Detected failing Integration Tests jobs – re-running failed jobs for this run."
47+
gh run rerun "$RUN_ID" --failed
48+
else
49+
echo "Only non-matrix jobs (like Test Results) failed – not auto-rerunning."
50+
fi

0 commit comments

Comments
 (0)