34
34
script : |
35
35
const failure_regex = /Process completed with exit code 1./
36
36
const preemption_regex = /The runner has received a shutdown signal/
37
-
37
+
38
38
const wf_run = context.payload.workflow_run
39
39
core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)
40
40
@@ -80,30 +80,30 @@ jobs:
80
80
}
81
81
check_run_ids.push(check_run.id);
82
82
}
83
-
83
+
84
84
has_preempted_job = false;
85
85
86
86
for (check_run_id of check_run_ids) {
87
87
console.log('Listing annotations for check run: ' + check_run_id);
88
-
88
+
89
89
annotations = await github.rest.checks.listAnnotations({
90
90
owner: context.repo.owner,
91
91
repo: context.repo.repo,
92
92
check_run_id: check_run_id
93
93
})
94
-
94
+
95
95
for (annotation of annotations.data) {
96
96
if (annotation.annotation_level != 'failure') {
97
97
continue;
98
98
}
99
-
99
+
100
100
const preemption_match = annotation.message.match(preemption_regex);
101
-
101
+
102
102
if (preemption_match != null) {
103
103
console.log('Found preemption message: ' + annotation.message);
104
104
has_preempted_job = true;
105
105
}
106
-
106
+
107
107
const failure_match = annotation.message.match(failure_regex);
108
108
if (failure_match != null) {
109
109
// We only want to restart the workflow if all of the failures were due to preemption.
@@ -115,20 +115,18 @@ jobs:
115
115
return;
116
116
}
117
117
}
118
- }
119
-
118
+ }
119
+
120
120
if (!has_preempted_job) {
121
121
core.notice('No preempted jobs found. Not restarting workflow.');
122
122
await create_check_run('neutral', 'No preempted jobs found. Not restarting workflow.')
123
123
return;
124
124
}
125
-
125
+
126
126
core.notice("Restarted workflow: " + context.payload.workflow_run.id);
127
127
await github.rest.actions.reRunWorkflowFailedJobs({
128
128
owner: context.repo.owner,
129
129
repo: context.repo.repo,
130
130
run_id: context.payload.workflow_run.id
131
131
})
132
132
await create_check_run('success', 'Restarted workflow run due to preempted job')
133
-
134
-
0 commit comments