-
Notifications
You must be signed in to change notification settings - Fork 24
91 lines (73 loc) · 3.73 KB
/
Copy pathrerun-ci.yaml
File metadata and controls
91 lines (73 loc) · 3.73 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Rerun Failed CI
on:
issue_comment:
types: [created]
permissions:
actions: write
pull-requests: write
issues: write
jobs:
rerun:
name: Rerun Failed Checks
if: >-
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/rerun')
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Rerun workflows
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR=${{ github.event.issue.number }}
REPO=${{ github.repository }}
COMMENT="${{ github.event.comment.body }}"
# Map comment keywords to workflow file names
declare -A WORKFLOW_MAP
WORKFLOW_MAP["/rerun-lint"]="code-checker.yaml"
WORKFLOW_MAP["/rerun-mod-tidy"]="code-checker.yaml"
WORKFLOW_MAP["/rerun-unit-test"]="unit-test.yaml"
WORKFLOW_MAP["/rerun-e2e-local"]="integration-test-e2e-local.yaml"
WORKFLOW_MAP["/rerun-e2e-objectstorage"]="integration-test-e2e-objectstorage.yaml"
WORKFLOW_MAP["/rerun-e2e-service"]="integration-test-e2e-service.yaml"
WORKFLOW_MAP["/rerun-component-test"]="integration-test-components.yaml"
WORKFLOW_MAP["/rerun-chaos"]="integration-test-chaos.yaml"
WORKFLOW_MAP["/rerun-operator"]="operator-test.yaml"
HEAD_SHA=$(gh pr view $PR --repo $REPO --json headRefOid -q '.headRefOid')
# Extract the first word as the command
CMD=$(echo "$COMMENT" | awk '{print $1}')
if [ "$CMD" = "/rerun" ]; then
# Rerun all failed workflows
FAILED_RUNS=$(gh api "repos/${REPO}/actions/runs?head_sha=${HEAD_SHA}&status=failure" \
--jq '.workflow_runs[].id')
if [ -z "$FAILED_RUNS" ]; then
gh pr comment $PR --repo $REPO --body "No failed workflow runs found for the latest commit."
exit 0
fi
COUNT=0
for run_id in $FAILED_RUNS; do
gh api "repos/${REPO}/actions/runs/${run_id}/rerun-failed-jobs" -X POST || true
COUNT=$((COUNT + 1))
done
gh pr comment $PR --repo $REPO --body "Rerunning $COUNT failed workflow(s). Check the [Actions tab](https://github.com/${REPO}/actions) for progress."
elif [ "$CMD" = "/rerun-all" ]; then
# Internal command: rerun ALL workflows (not just failed), no comment posted
ALL_RUNS=$(gh api "repos/${REPO}/actions/runs?head_sha=${HEAD_SHA}" \
--jq '.workflow_runs[].id')
for run_id in $ALL_RUNS; do
gh api "repos/${REPO}/actions/runs/${run_id}/rerun" -X POST || true
done
elif [ -n "${WORKFLOW_MAP[$CMD]+x}" ]; then
# Rerun a specific workflow
WORKFLOW_FILE="${WORKFLOW_MAP[$CMD]}"
RUN_ID=$(gh api "repos/${REPO}/actions/runs?head_sha=${HEAD_SHA}" \
--jq ".workflow_runs[] | select(.path == \".github/workflows/${WORKFLOW_FILE}\") | .id" | head -1)
if [ -z "$RUN_ID" ]; then
gh pr comment $PR --repo $REPO --body "No workflow run found for \`${CMD}\` on the latest commit."
exit 0
fi
gh api "repos/${REPO}/actions/runs/${RUN_ID}/rerun" -X POST
gh pr comment $PR --repo $REPO --body "Rerunning **${CMD#/rerun-}** workflow. Check the [Actions tab](https://github.com/${REPO}/actions) for progress."
else
gh pr comment $PR --repo $REPO --body "Unknown command \`${CMD}\`. Available commands: \`/rerun\`, \`/rerun-lint\`, \`/rerun-mod-tidy\`, \`/rerun-unit-test\`, \`/rerun-e2e-local\`, \`/rerun-e2e-objectstorage\`, \`/rerun-e2e-service\`, \`/rerun-component-test\`, \`/rerun-chaos\`, \`/rerun-operator\`."
fi