@@ -33,12 +33,13 @@ async function getWorkflowRun(
33
33
async function getWorkflowRunRetrying (
34
34
octokit : ReturnType < typeof github . getOctokit > ,
35
35
expectedRunName : string ,
36
+ expectedRunAttempt : number ,
36
37
pollDelayMs = 1000
37
38
) {
38
39
for ( let attempt = 0 ; attempt < MAX_GET_LATEST_ATTEMPTS ; attempt ++ ) {
39
40
const run = await getWorkflowRun ( octokit , expectedRunName ) ;
40
41
debug ( `Attempt %d finding run named "%s"` , attempt , expectedRunName ) ;
41
- if ( run ) {
42
+ if ( run && run . run_attempt === expectedRunAttempt ) {
42
43
return run ;
43
44
}
44
45
await new Promise ( ( resolve ) => setTimeout ( resolve , pollDelayMs ) ) ;
@@ -129,6 +130,11 @@ type DispatchOptions = {
129
130
* Delay in milliseconds to wait between requests when polling while watching the run.
130
131
*/
131
132
watchPollDelayMs ?: number | undefined ;
133
+
134
+ /**
135
+ * How many times should a failed job be retried.
136
+ */
137
+ retries ?: number | undefined ;
132
138
} ;
133
139
134
140
export async function dispatchAndWait ( {
@@ -140,6 +146,7 @@ export async function dispatchAndWait({
140
146
githubPrNumber,
141
147
evergreenTaskUrl,
142
148
watchPollDelayMs = 5000 ,
149
+ retries = 3 ,
143
150
} : DispatchOptions ) {
144
151
const octokit = github . getOctokit ( githubToken ) ;
145
152
const nonce = createNonce ( ) ;
@@ -159,20 +166,37 @@ export async function dispatchAndWait({
159
166
} ,
160
167
} ) ;
161
168
162
- // Find the next run we just dispatched
163
- const run = await getWorkflowRunRetrying (
164
- octokit ,
165
- `Test Installers ${ devVersion || ref } / (nonce = ${ nonce } )`
166
- ) ;
169
+ for ( let attempt = 1 ; attempt <= retries ; attempt ++ ) {
170
+ // Find the next run we just dispatched
171
+ const run = await getWorkflowRunRetrying (
172
+ octokit ,
173
+ // Matching on the run name, as defined by the workflow in `.github/workflows/test-installers.yml`
174
+ `Test Installers ${ devVersion || ref } / (nonce = ${ nonce } )` ,
175
+ attempt
176
+ ) ;
177
+
178
+ console . log (
179
+ `Dispatched run #${ run . run_number } (attempt ${ attempt } / ${ retries } ) (${ run . html_url } )`
180
+ ) ;
181
+ const status = await pollToCompletion ( {
182
+ octokit,
183
+ runId : run . id ,
184
+ watchTimeoutMs : WATCH_POLL_TIMEOUT_MS ,
185
+ watchPollDelayMs,
186
+ } ) ;
167
187
168
- console . log ( `Dispatched run #${ run . run_number } (${ run . html_url } )` ) ;
169
- const status = await pollToCompletion ( {
170
- octokit,
171
- runId : run . id ,
172
- watchTimeoutMs : WATCH_POLL_TIMEOUT_MS ,
173
- watchPollDelayMs,
174
- } ) ;
188
+ console . log ( `Run completed (status = ${ status } ): ${ run . html_url } ` ) ;
189
+ if ( status === 'success' ) {
190
+ return ;
191
+ } else {
192
+ console . log ( 'Re-running failed jobs' ) ;
193
+ await octokit . rest . actions . reRunWorkflowFailedJobs ( {
194
+ owner : GITHUB_OWNER ,
195
+ repo : GITHUB_REPO ,
196
+ run_id : run . id ,
197
+ } ) ;
198
+ }
199
+ }
175
200
176
- console . log ( `Run completed: ${ run . html_url } ` ) ;
177
- assert . equal ( status , 'success' , "Expected a 'success' conclusion" ) ;
201
+ throw new Error ( 'All attempts to run the workflow failed!' ) ;
178
202
}
0 commit comments