-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathrerun-ci-on-skipped-e2e-labels.yml
More file actions
99 lines (84 loc) · 3.17 KB
/
rerun-ci-on-skipped-e2e-labels.yml
File metadata and controls
99 lines (84 loc) · 3.17 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
92
93
94
95
96
97
98
99
name: Rerun CI on skipped E2E labels
on:
pull_request:
types: [labeled, unlabeled]
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_REF: ${{ github.head_ref }}
jobs:
rerun-ci:
if: >-
github.event.label.name == 'skip-smart-e2e-selection' ||
github.event.label.name == 'skip-e2e' ||
github.event.label.name == 'skip-e2e-flakiness-detection' ||
github.event.label.name == 'pr-not-ready-for-e2e'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Cancel running CI workflows
id: cancel
run: |
echo "Looking for CI runs on branch $HEAD_REF..."
CANCELLED=false
while read -r RUN_ID; do
if [ -n "$RUN_ID" ]; then
echo "Cancelling run $RUN_ID..."
gh run cancel "$RUN_ID" --repo "$REPO" || true
CANCELLED=true
fi
done < <(gh run list \
--repo "$REPO" \
--branch "$HEAD_REF" \
--workflow "ci.yml" \
--json databaseId,status \
--jq '.[] | select(.status == "in_progress" or .status == "queued") | .databaseId')
echo "cancelled=$CANCELLED" >> "$GITHUB_OUTPUT"
- name: Find latest CI workflow run
id: find
run: |
LATEST_RUN_ID=$(gh run list \
--repo "$REPO" \
--branch "$HEAD_REF" \
--workflow "ci.yml" \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId')
if [ -z "$LATEST_RUN_ID" ] || [ "$LATEST_RUN_ID" = "null" ]; then
echo "No CI workflow run found for branch $HEAD_REF"
exit 0
fi
echo "run_id=$LATEST_RUN_ID" >> "$GITHUB_OUTPUT"
- name: Wait for cancellation to complete
if: steps.cancel.outputs.cancelled == 'true' && steps.find.outputs.run_id
run: |
RUN_ID="${{ steps.find.outputs.run_id }}"
MAX_WAIT=600
ELAPSED=0
echo "Waiting up to ${MAX_WAIT}s for workflow to finish cancelling..."
while [ $ELAPSED -lt $MAX_WAIT ]; do
STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq '.status')
echo "Status: $STATUS (${ELAPSED}s elapsed)"
if [ "$STATUS" != "in_progress" ] && [ "$STATUS" != "queued" ]; then
echo "Workflow ready for rerun"
break
fi
sleep 15
ELAPSED=$((ELAPSED + 15))
done
FINAL_STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq '.status')
if [ "$FINAL_STATUS" = "in_progress" ] || [ "$FINAL_STATUS" = "queued" ]; then
echo "Timeout: workflow still $FINAL_STATUS after ${MAX_WAIT}s"
exit 1
fi
- name: Rerun CI workflow
if: steps.find.outputs.run_id
run: |
RUN_ID="${{ steps.find.outputs.run_id }}"
echo "Re-running workflow $RUN_ID..."
if gh run rerun "$RUN_ID" --repo "$REPO"; then
echo "CI workflow re-triggered successfully"
else
echo "Rerun not possible (run may not be in a retriable state)"
fi