@@ -83,7 +83,18 @@ describe('execute', () => {
83
83
'target event: \x1b[32;40mpush\x1b[0m' ,
84
84
'target branch: \x1b[32;40mrelease/v1.2.3\x1b[0m' ,
85
85
'::group::workflow runs:' ,
86
- getLogStdout ( [ ] ) ,
86
+ getLogStdout ( [
87
+ {
88
+ 'id' : 30433642 ,
89
+ 'head_branch' : 'master' ,
90
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
91
+ 'run_number' : 562 ,
92
+ 'event' : 'push' ,
93
+ 'status' : 'queued' ,
94
+ 'created_at' : '2020-01-22T19:33:08Z' ,
95
+ 'updated_at' : '2020-02-22T19:33:08Z' ,
96
+ } ,
97
+ ] ) ,
87
98
'::endgroup::' ,
88
99
'' ,
89
100
'::group::Cancelling...' ,
@@ -293,4 +304,122 @@ describe('execute', () => {
293
304
294
305
expect ( sleepFn ) . toBeCalledWith ( 123 ) ;
295
306
} ) ;
307
+
308
+ it ( 'should cancel jobs (get workflow runs api not contains this run)' , async ( ) => {
309
+ // workflow-run.list
310
+ // 30433642 run_number=562, updated_at=2020-02-22T19:33:08Z (re-run) => expected that this will be cancelled
311
+ // 30433643 run_number=563, updated_at=2020-01-23T19:33:08Z (merge commit) => expected that this will be cancelled
312
+ // 30433644 run_number=564, updated_at=2020-01-24T19:33:08Z => expected that this will be cancelled
313
+ // 30433645 run_number=565, updated_at=2020-01-25T19:33:08Z => expected that this will be cancelled
314
+ // 30433646 run_number=566, updated_at=2020-01-25T19:33:08Z (target run) => expected that this will not be cancelled
315
+ // 30433646~30433649 (different event) => expected that this will not be cancelled
316
+
317
+ const mockStdout = spyOnStdout ( ) ;
318
+ nock ( 'https://api.github.com' )
319
+ . get ( '/repos/hello/world/actions/runs/30433646' )
320
+ . reply ( 200 , ( ) => getApiFixture ( fixturesDir , 'workflow-run.get.30433646' ) )
321
+ . get ( '/repos/hello/world/actions/workflows/111566/runs?status=in_progress&branch=release%2Fv1.2.3' )
322
+ . reply ( 200 , ( ) => getApiFixture ( fixturesDir , 'workflow-run.list' ) )
323
+ . post ( '/repos/hello/world/actions/runs/30433642/cancel' )
324
+ . reply ( 202 )
325
+ . post ( '/repos/hello/world/actions/runs/30433643/cancel' )
326
+ . reply ( 202 )
327
+ . post ( '/repos/hello/world/actions/runs/30433644/cancel' )
328
+ . reply ( 202 )
329
+ . post ( '/repos/hello/world/actions/runs/30433645/cancel' )
330
+ . reply ( 202 ) ;
331
+
332
+ await execute ( new Logger ( ) , getOctokit ( ) , generateContext ( { owner : 'hello' , repo : 'world' , event : 'pull_request' } , {
333
+ runId : 30433646 ,
334
+ payload : {
335
+ 'pull_request' : {
336
+ head : {
337
+ ref : 'release/v1.2.3' ,
338
+ } ,
339
+ } ,
340
+ } ,
341
+ } ) ) ;
342
+
343
+ stdoutCalledWith ( mockStdout , [
344
+ '> run id: 30433646' ,
345
+ '::group::run:' ,
346
+ getLogStdout ( {
347
+ 'id' : 30433646 ,
348
+ 'head_branch' : 'master' ,
349
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
350
+ 'run_number' : 566 ,
351
+ 'event' : 'push' ,
352
+ 'status' : 'queued' ,
353
+ 'created_at' : '2020-01-24T19:33:08Z' ,
354
+ 'updated_at' : '2020-01-24T19:33:08Z' ,
355
+ } ) ,
356
+ '::endgroup::' ,
357
+ '> workflow id: 111566' ,
358
+ 'target event: \x1b[32;40mpull_request\x1b[0m' ,
359
+ 'target branch: \x1b[32;40mrelease/v1.2.3\x1b[0m' ,
360
+ '::group::workflow runs:' ,
361
+ getLogStdout ( [
362
+ {
363
+ 'id' : 30433642 ,
364
+ 'head_branch' : 'master' ,
365
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
366
+ 'run_number' : 562 ,
367
+ 'event' : 'pull_request' ,
368
+ 'status' : 'queued' ,
369
+ 'created_at' : '2020-01-22T19:33:08Z' ,
370
+ 'updated_at' : '2020-02-22T19:33:08Z' ,
371
+ } ,
372
+ {
373
+ 'id' : 30433643 ,
374
+ 'head_branch' : 'master' ,
375
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
376
+ 'run_number' : 563 ,
377
+ 'event' : 'pull_request' ,
378
+ 'status' : 'queued' ,
379
+ 'created_at' : '2020-01-23T19:33:08Z' ,
380
+ 'updated_at' : '2020-01-23T19:33:08Z' ,
381
+ } ,
382
+ {
383
+ 'id' : 30433644 ,
384
+ 'head_branch' : 'master' ,
385
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
386
+ 'run_number' : 564 ,
387
+ 'event' : 'pull_request' ,
388
+ 'status' : 'queued' ,
389
+ 'created_at' : '2020-01-24T19:33:08Z' ,
390
+ 'updated_at' : '2020-01-24T19:33:08Z' ,
391
+ } ,
392
+ {
393
+ 'id' : 30433645 ,
394
+ 'head_branch' : 'master' ,
395
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
396
+ 'run_number' : 565 ,
397
+ 'event' : 'pull_request' ,
398
+ 'status' : 'queued' ,
399
+ 'created_at' : '2020-01-25T19:33:08Z' ,
400
+ 'updated_at' : '2020-01-25T19:33:08Z' ,
401
+ } ,
402
+ {
403
+ 'id' : 30433646 ,
404
+ 'head_branch' : 'master' ,
405
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
406
+ 'run_number' : 566 ,
407
+ 'event' : 'push' ,
408
+ 'status' : 'queued' ,
409
+ 'created_at' : '2020-01-24T19:33:08Z' ,
410
+ 'updated_at' : '2020-01-24T19:33:08Z' ,
411
+ } ,
412
+ ] ) ,
413
+ '::endgroup::' ,
414
+ '' ,
415
+ '::group::Cancelling...' ,
416
+ 'cancel: 30433642' ,
417
+ 'cancel: 30433643' ,
418
+ 'cancel: 30433644' ,
419
+ 'cancel: 30433645' ,
420
+ '> total: 4' ,
421
+ '::set-output name=ids::30433642,30433643,30433644,30433645' ,
422
+ '::endgroup::' ,
423
+ ] ) ;
424
+ } ) ;
296
425
} ) ;
0 commit comments