3434 script : |
3535 const failure_regex = /Process completed with exit code 1./
3636 const preemption_regex = /The runner has received a shutdown signal/
37-
37+
3838 const wf_run = context.payload.workflow_run
3939 core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)
4040
@@ -80,30 +80,30 @@ jobs:
8080 }
8181 check_run_ids.push(check_run.id);
8282 }
83-
83+
8484 has_preempted_job = false;
8585
8686 for (check_run_id of check_run_ids) {
8787 console.log('Listing annotations for check run: ' + check_run_id);
88-
88+
8989 annotations = await github.rest.checks.listAnnotations({
9090 owner: context.repo.owner,
9191 repo: context.repo.repo,
9292 check_run_id: check_run_id
9393 })
94-
94+
9595 for (annotation of annotations.data) {
9696 if (annotation.annotation_level != 'failure') {
9797 continue;
9898 }
99-
99+
100100 const preemption_match = annotation.message.match(preemption_regex);
101-
101+
102102 if (preemption_match != null) {
103103 console.log('Found preemption message: ' + annotation.message);
104104 has_preempted_job = true;
105105 }
106-
106+
107107 const failure_match = annotation.message.match(failure_regex);
108108 if (failure_match != null) {
109109 // We only want to restart the workflow if all of the failures were due to preemption.
@@ -115,20 +115,18 @@ jobs:
115115 return;
116116 }
117117 }
118- }
119-
118+ }
119+
120120 if (!has_preempted_job) {
121121 core.notice('No preempted jobs found. Not restarting workflow.');
122122 await create_check_run('neutral', 'No preempted jobs found. Not restarting workflow.')
123123 return;
124124 }
125-
125+
126126 core.notice("Restarted workflow: " + context.payload.workflow_run.id);
127127 await github.rest.actions.reRunWorkflowFailedJobs({
128128 owner: context.repo.owner,
129129 repo: context.repo.repo,
130130 run_id: context.payload.workflow_run.id
131131 })
132132 await create_check_run('success', 'Restarted workflow run due to preempted job')
133-
134-
0 commit comments