Skip to content

Commit cc18e3d

Browse files
authored
Create rerun.yml
1 parent 4c1f55a commit cc18e3d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/rerun.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Auto-rerun (Uninstall .NET SDKs failure)
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types: [completed]
7+
8+
permissions:
9+
actions: write
10+
contents: read
11+
12+
jobs:
13+
rerun_if_uninstall_dotnet_failed:
14+
if: >
15+
github.event.workflow_run.conclusion == 'failure' &&
16+
github.event.workflow_run.run_attempt < 3
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Decide whether to rerun
21+
id: decide
22+
env:
23+
GH_TOKEN: ${{ github.token }}
24+
REPO: ${{ github.repository }}
25+
RUN_ID: ${{ github.event.workflow_run.id }}
26+
STEP_NAME: "Uninstall .NET SDKs"
27+
shell: bash
28+
run: |
29+
set -euo pipefail
30+
31+
# Fetch jobs + steps for the failed workflow run
32+
jobs_json="$(gh api -H "Accept: application/vnd.github+json" \
33+
"/repos/${REPO}/actions/runs/${RUN_ID}/jobs?per_page=100")"
34+
35+
# Check whether the specific step failed
36+
if echo "$jobs_json" | jq -e --arg step "$STEP_NAME" '
37+
.jobs[].steps[]? | select(.name == $step and .conclusion == "failure")
38+
' >/dev/null; then
39+
echo "rerun=true" >> "$GITHUB_OUTPUT"
40+
echo "Detected failure in step: $STEP_NAME"
41+
else
42+
echo "rerun=false" >> "$GITHUB_OUTPUT"
43+
echo "No failure in step '$STEP_NAME' detected; not rerunning."
44+
fi
45+
46+
- name: Rerun failed jobs
47+
if: steps.decide.outputs.rerun == 'true'
48+
env:
49+
GH_TOKEN: ${{ github.token }}
50+
REPO: ${{ github.repository }}
51+
RUN_ID: ${{ github.event.workflow_run.id }}
52+
shell: bash
53+
run: |
54+
gh run rerun "$RUN_ID" -R "$REPO" --failed

0 commit comments

Comments
 (0)