Skip to content

Commit 28c39b6

Browse files
authored
chore(ci): add automatic rerun controller for flaky workflows (#2984)
* ci: increase retry delay for rerun jobs from 60 to 180 seconds
1 parent 06097c8 commit 28c39b6

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/rerun-ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "Rerun CI"
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- "HugeGraph-Server CI"
7+
- "HugeGraph-Commons CI"
8+
- "HugeGraph-PD & Store & Hstore CI"
9+
- "Cluster Test CI"
10+
types:
11+
- completed
12+
13+
permissions: {}
14+
15+
env:
16+
MAX_RERUNS: '2'
17+
RETRY_DELAY_SECONDS: '180'
18+
19+
jobs:
20+
decide-rerun-action:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
action: ${{ steps.decision.outputs.action }}
24+
steps:
25+
- name: Decide rerun action
26+
id: decision
27+
env:
28+
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
29+
RUN_ID: ${{ github.event.workflow_run.id }}
30+
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
31+
CONCLUSION: ${{ github.event.workflow_run.conclusion }}
32+
EVENT_NAME: ${{ github.event.workflow_run.event }}
33+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
34+
run: |
35+
set -euo pipefail
36+
37+
action="skip"
38+
reason="non-failure"
39+
40+
if [[ "$CONCLUSION" == "failure" ]]; then
41+
if [[ "$EVENT_NAME" != "push" && "$EVENT_NAME" != "pull_request" ]]; then
42+
reason="unsupported event: $EVENT_NAME"
43+
elif (( RUN_ATTEMPT > MAX_RERUNS )); then
44+
reason="retry limit reached"
45+
else
46+
action="rerun"
47+
reason="within retry limit"
48+
fi
49+
fi
50+
51+
{
52+
echo "action=$action"
53+
echo "reason=$reason"
54+
} >> "$GITHUB_OUTPUT"
55+
56+
{
57+
echo "### Rerun CI decision"
58+
echo ""
59+
echo "- Workflow: $WORKFLOW_NAME"
60+
echo "- Source event: $EVENT_NAME"
61+
echo "- Head branch: $HEAD_BRANCH"
62+
echo "- Run ID: $RUN_ID"
63+
echo "- Current attempt: $RUN_ATTEMPT"
64+
echo "- Max automatic reruns: $MAX_RERUNS"
65+
echo "- Delay seconds: $RETRY_DELAY_SECONDS"
66+
echo "- Action: $action"
67+
echo "- Reason: $reason"
68+
} >> "$GITHUB_STEP_SUMMARY"
69+
70+
rerun-failed-jobs:
71+
needs: decide-rerun-action
72+
if: needs.decide-rerun-action.outputs.action == 'rerun'
73+
permissions:
74+
actions: write
75+
contents: read
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Wait before rerun
79+
run: |
80+
sleep "$RETRY_DELAY_SECONDS"
81+
82+
- name: Rerun failed jobs
83+
env:
84+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
GH_REPO: ${{ github.repository }}
86+
run: |
87+
gh run rerun ${{ github.event.workflow_run.id }} --failed

0 commit comments

Comments
 (0)