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