-
Notifications
You must be signed in to change notification settings - Fork 1
69 lines (62 loc) · 2.28 KB
/
deflake_tests.yaml
File metadata and controls
69 lines (62 loc) · 2.28 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
name: Deflake Tests
description: Re-triggers test jobs if they failed.
on:
workflow_run:
workflows: [linux]
types:
- completed
jobs:
rerun-failing-jobs:
runs-on: ubuntu-latest
# if: github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled'
permissions:
actions: write
checks: read
steps:
- name: Download CI Essentials
uses: actions/download-artifact@v4
with:
pattern: ci-essentials-*
merge-multiple: true
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check Retry Count
id: retry_check
env:
DEFLAKE_ATTEMPTS: 3
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_REF: ${{ github.event.workflow_run.pull_requests[0].head.ref }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
WORKFLOW: ${{ github.event.workflow_run.id }}
shell: bash
run: |
set +x
# Attempt to access the last attempt of the workflow that triggereed this one.
if gh run view ${WORKFLOW} --attempt ${DEFLAKE_ATTEMPTS}; then
echo "continue=false" >> ${GITHUB_OUTPUT}
else
echo "continue=true" >> ${GITHUB_OUTPUT}
fi
- name: Rerun Failing Checks
if: steps.retry_check.outputs.continue == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
REPO: ${{ github.repository }}
shell: bash
run: |
set +x
echo "Fetching failing checks for PR #${PR_NUMBER}"
failing_runs=$(gh pr checks "${PR_NUMBER}" --repo "${REPO}" | grep -E 'fail|cancel')
if [ -z "${failing_runs}" ]; then
echo "No failing checks found to rerun."
exit 0
fi
run_ids_to_rerun=$(echo "${failing_runs}" | python3 ./.github/scripts/extract_run_ids.py)
if [ -z "${run_ids_to_rerun}" ]; then
echo "Could not extract run IDs from failing checks."
exit 0
fi
for run_id in ${run_ids_to_rerun}; do
gh run rerun "${run_id}" --repo "${REPO}"
done