Skip to content

Commit af40258

Browse files
committed
ci: refine auto rerun controller policy
1 parent f320ec4 commit af40258

1 file changed

Lines changed: 57 additions & 8 deletions

File tree

.github/workflows/rerun-ci.yml

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,75 @@ on:
99
- "Cluster Test CI"
1010
types:
1111
- completed
12+
branches:
13+
- master
14+
- 'release-*'
15+
- 'test-*'
1216

1317
permissions:
1418
actions: write
1519
contents: read
1620

21+
env:
22+
MAX_RERUNS: '2'
23+
RETRY_DELAY_SECONDS: '180'
24+
1725
jobs:
1826
rerun-failed-jobs:
19-
if: >-
20-
github.event.workflow_run.conclusion == 'failure' &&
21-
fromJSON(github.event.workflow_run.run_attempt) < 2
2227
runs-on: ubuntu-latest
2328
steps:
24-
- name: Show rerun target
29+
- name: Decide rerun action
30+
id: decision
31+
env:
32+
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
33+
RUN_ID: ${{ github.event.workflow_run.id }}
34+
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
35+
CONCLUSION: ${{ github.event.workflow_run.conclusion }}
36+
EVENT_NAME: ${{ github.event.workflow_run.event }}
37+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
38+
run: |
39+
set -euo pipefail
40+
41+
action="skip"
42+
reason="non-failure"
43+
44+
if [[ "$CONCLUSION" == "failure" ]]; then
45+
if [[ "$EVENT_NAME" != "push" && "$EVENT_NAME" != "pull_request" ]]; then
46+
reason="unsupported event: $EVENT_NAME"
47+
elif (( RUN_ATTEMPT > MAX_RERUNS )); then
48+
reason="retry limit reached"
49+
else
50+
action="rerun"
51+
reason="within retry limit"
52+
fi
53+
fi
54+
55+
{
56+
echo "action=$action"
57+
echo "reason=$reason"
58+
} >> "$GITHUB_OUTPUT"
59+
60+
{
61+
echo "### Rerun CI decision"
62+
echo ""
63+
echo "- Workflow: $WORKFLOW_NAME"
64+
echo "- Source event: $EVENT_NAME"
65+
echo "- Head branch: $HEAD_BRANCH"
66+
echo "- Run ID: $RUN_ID"
67+
echo "- Current attempt: $RUN_ATTEMPT"
68+
echo "- Max automatic reruns: $MAX_RERUNS"
69+
echo "- Delay seconds: $RETRY_DELAY_SECONDS"
70+
echo "- Action: $action"
71+
echo "- Reason: $reason"
72+
} >> "$GITHUB_STEP_SUMMARY"
73+
74+
- name: Wait before rerun
75+
if: steps.decision.outputs.action == 'rerun'
2576
run: |
26-
echo "Workflow: ${{ github.event.workflow_run.name }}"
27-
echo "Run ID: ${{ github.event.workflow_run.id }}"
28-
echo "Run attempt: ${{ github.event.workflow_run.run_attempt }}"
29-
echo "Conclusion: ${{ github.event.workflow_run.conclusion }}"
77+
sleep "$RETRY_DELAY_SECONDS"
3078
3179
- name: Rerun failed jobs
80+
if: steps.decision.outputs.action == 'rerun'
3281
env:
3382
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3483
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)