@@ -422,4 +422,116 @@ describe('execute', () => {
422
422
'::endgroup::' ,
423
423
] ) ;
424
424
} ) ;
425
+
426
+ it ( 'should cancel jobs (some workflow runs fail to cancel)' , async ( ) => {
427
+ // workflow-run.list
428
+ // 30433642 run_number=562, updated_at=2020-02-22T19:33:08Z (re-run) => expected that this will be cancelled (fail)
429
+ // 30433643 run_number=563, updated_at=2020-01-23T19:33:08Z (merge commit) => expected that this will be cancelled
430
+ // 30433644 run_number=564, updated_at=2020-01-24T19:33:08Z (target run) => expected that this will be cancelled (fail)
431
+ // 30433645 run_number=565, updated_at=2020-01-25T19:33:08Z => expected that this will not be cancelled
432
+ // 30433646~30433649 (different event) => expected that this will not be cancelled
433
+
434
+ const mockStdout = spyOnStdout ( ) ;
435
+ nock ( 'https://api.github.com' )
436
+ . get ( '/repos/hello/world/actions/runs/30433644' )
437
+ . reply ( 200 , ( ) => getApiFixture ( fixturesDir , 'workflow-run.get.30433644' ) )
438
+ . get ( '/repos/hello/world/actions/workflows/111564/runs?status=in_progress&branch=release%2Fv1.2.3' )
439
+ . reply ( 200 , ( ) => getApiFixture ( fixturesDir , 'workflow-run.list' ) )
440
+ . post ( '/repos/hello/world/actions/runs/30433642/cancel' )
441
+ . replyWithError ( {
442
+ message : 'Cannot cancel a workflow run that is completed.' ,
443
+ code : 409 ,
444
+ } )
445
+ . post ( '/repos/hello/world/actions/runs/30433643/cancel' )
446
+ . reply ( 202 )
447
+ . post ( '/repos/hello/world/actions/runs/30433644/cancel' )
448
+ . replyWithError ( {
449
+ message : 'Cannot cancel a workflow run that is completed.' ,
450
+ code : 409 ,
451
+ } ) ;
452
+
453
+ await execute ( new Logger ( ) , getOctokit ( ) , generateContext ( { owner : 'hello' , repo : 'world' , event : 'pull_request' } , {
454
+ runId : 30433644 ,
455
+ payload : {
456
+ 'pull_request' : {
457
+ head : {
458
+ ref : 'release/v1.2.3' ,
459
+ } ,
460
+ } ,
461
+ } ,
462
+ } ) ) ;
463
+
464
+ stdoutCalledWith ( mockStdout , [
465
+ '> run id: 30433644' ,
466
+ '::group::run:' ,
467
+ getLogStdout ( {
468
+ 'id' : 30433644 ,
469
+ 'head_branch' : 'master' ,
470
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
471
+ 'run_number' : 564 ,
472
+ 'event' : 'push' ,
473
+ 'status' : 'queued' ,
474
+ 'created_at' : '2020-01-24T19:33:08Z' ,
475
+ 'updated_at' : '2020-01-24T19:33:08Z' ,
476
+ } ) ,
477
+ '::endgroup::' ,
478
+ '> workflow id: 111564' ,
479
+ 'target event: \x1b[32;40mpull_request\x1b[0m' ,
480
+ 'target branch: \x1b[32;40mrelease/v1.2.3\x1b[0m' ,
481
+ '::group::workflow runs:' ,
482
+ getLogStdout ( [
483
+ {
484
+ 'id' : 30433642 ,
485
+ 'head_branch' : 'master' ,
486
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
487
+ 'run_number' : 562 ,
488
+ 'event' : 'pull_request' ,
489
+ 'status' : 'queued' ,
490
+ 'created_at' : '2020-01-22T19:33:08Z' ,
491
+ 'updated_at' : '2020-02-22T19:33:08Z' ,
492
+ } ,
493
+ {
494
+ 'id' : 30433643 ,
495
+ 'head_branch' : 'master' ,
496
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
497
+ 'run_number' : 563 ,
498
+ 'event' : 'pull_request' ,
499
+ 'status' : 'queued' ,
500
+ 'created_at' : '2020-01-23T19:33:08Z' ,
501
+ 'updated_at' : '2020-01-23T19:33:08Z' ,
502
+ } ,
503
+ {
504
+ 'id' : 30433644 ,
505
+ 'head_branch' : 'master' ,
506
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
507
+ 'run_number' : 564 ,
508
+ 'event' : 'pull_request' ,
509
+ 'status' : 'queued' ,
510
+ 'created_at' : '2020-01-24T19:33:08Z' ,
511
+ 'updated_at' : '2020-01-24T19:33:08Z' ,
512
+ } ,
513
+ {
514
+ 'id' : 30433645 ,
515
+ 'head_branch' : 'master' ,
516
+ 'head_sha' : 'acb5820ced9479c074f688cc328bf03f341a511d' ,
517
+ 'run_number' : 565 ,
518
+ 'event' : 'pull_request' ,
519
+ 'status' : 'queued' ,
520
+ 'created_at' : '2020-01-25T19:33:08Z' ,
521
+ 'updated_at' : '2020-01-25T19:33:08Z' ,
522
+ } ,
523
+ ] ) ,
524
+ '::endgroup::' ,
525
+ '' ,
526
+ '::group::Cancelling...' ,
527
+ 'cancel: 30433642' ,
528
+ '::error::request to https://api.github.com/repos/hello/world/actions/runs/30433642/cancel failed, reason: Cannot cancel a workflow run that is completed.' ,
529
+ 'cancel: 30433643' ,
530
+ 'cancel: 30433644' ,
531
+ '::error::request to https://api.github.com/repos/hello/world/actions/runs/30433644/cancel failed, reason: Cannot cancel a workflow run that is completed.' ,
532
+ '> total: 3' ,
533
+ '::set-output name=ids::30433642,30433643,30433644' ,
534
+ '::endgroup::' ,
535
+ ] ) ;
536
+ } ) ;
425
537
} ) ;
0 commit comments