-
Notifications
You must be signed in to change notification settings - Fork 680
134 lines (119 loc) · 4.47 KB
/
Copy pathrerun.yaml
File metadata and controls
134 lines (119 loc) · 4.47 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Rerun Job
on:
workflow_dispatch:
inputs:
run_id:
required: true
workflow_run:
workflows: [Tests]
types:
- completed
jobs:
rerun:
if: github.event_name == 'workflow_dispatch'
permissions:
actions: write
contents: read
pull-requests: read
runs-on: ubuntu-latest
steps:
- name: rerun ${{ inputs.run_id }}
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
run: |
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
gh run rerun ${{ inputs.run_id }} --failed
rerun-pr:
if: github.event.workflow_run && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.run_attempt < 5
permissions:
actions: write
contents: read
pull-requests: read
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
MAX_FAILED_TASKS: 30
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Get PR number
uses: actions/github-script@v9
with:
script: |
let page = 1;
let per_page = 100;
let allArtifacts = [];
let response;
do {
response = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
per_page: per_page,
page: page
});
allArtifacts = allArtifacts.concat(response.data.artifacts);
page++;
} while (allArtifacts.length < response.data.total_count);
let matchArtifact = allArtifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: Unzip PR number
run: unzip pr_number.zip
- name: Check for rerun eligibility
id: eligibility
run: |
source .github/scripts/common.sh
pr_number=$(cat pr_number)
GH_RETRY_CONTEXT="PR #$pr_number view lookup"
if ! pr_json=$(gh_retry pr view "$pr_number" --json number,isDraft,labels,reviews,baseRefName); then
echo "Failed to fetch PR details after retries"
echo "auto_rerun=false" >> "$GITHUB_OUTPUT"
GH_RETRY_CONTEXT=""
exit 0
fi
GH_RETRY_CONTEXT=""
if ! pr_is_rerun_eligible "$pr_json" 1 true; then
echo "setting auto rerun to false because $NOT_RERUN_REASON"
echo "auto_rerun=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "auto_rerun=true" >> "$GITHUB_OUTPUT"
echo "PR_NUMBER=$pr_number" >> "$GITHUB_ENV"
echo "PR_BASE=$(echo "$pr_json" | jq -r '.baseRefName // empty')" >> "$GITHUB_ENV"
- name: Set run ID
if: steps.eligibility.outputs.auto_rerun == 'true'
run: |
run_id=$(awk -F'/' '{print $(NF-1)}' <<<"${{ github.event.workflow_run.rerun_url }}")
echo "RUN_ID=$run_id" >> $GITHUB_ENV
- name: Check number of required system failures
id: threshold
if: steps.eligibility.outputs.auto_rerun == 'true'
run: |
source .github/scripts/common.sh
if ! required_spread_failure_threshold_allows_rerun "$RUN_ID" "$PR_BASE" "$GH_REPO" "$MAX_FAILED_TASKS"; then
echo "Setting rerun to false because $NOT_RERUN_REASON"
echo "threshold_ok=false" >> "$GITHUB_OUTPUT"
else
echo "threshold_ok=true" >> "$GITHUB_OUTPUT"
fi
- name: Rerun workflow
if: steps.eligibility.outputs.auto_rerun == 'true' && steps.threshold.outputs.threshold_ok == 'true'
run: |
source .github/scripts/common.sh
GH_RETRY_CONTEXT="rerun workflow for run_id=$RUN_ID"
if ! gh_retry run rerun "$RUN_ID" --failed; then
GH_RETRY_CONTEXT=""
exit 1
fi
GH_RETRY_CONTEXT=""