1- module . exports =
21/******/ ( ( ) => { // webpackBootstrap
32/******/ var __webpack_modules__ = ( {
43
@@ -5812,124 +5811,6 @@ function wrappy (fn, cb) {
58125811}
58135812
58145813
5815- /***/ } ) ,
5816-
5817- /***/ 144 :
5818- /***/ ( function ( __unused_webpack_module , exports , __nccwpck_require__ ) {
5819-
5820- "use strict" ;
5821-
5822- var __createBinding = ( this && this . __createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
5823- if ( k2 === undefined ) k2 = k ;
5824- Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
5825- } ) : ( function ( o , m , k , k2 ) {
5826- if ( k2 === undefined ) k2 = k ;
5827- o [ k2 ] = m [ k ] ;
5828- } ) ) ;
5829- var __setModuleDefault = ( this && this . __setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
5830- Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
5831- } ) : function ( o , v ) {
5832- o [ "default" ] = v ;
5833- } ) ;
5834- var __importStar = ( this && this . __importStar ) || function ( mod ) {
5835- if ( mod && mod . __esModule ) return mod ;
5836- var result = { } ;
5837- if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) __createBinding ( result , mod , k ) ;
5838- __setModuleDefault ( result , mod ) ;
5839- return result ;
5840- } ;
5841- Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
5842- const core = __importStar ( __nccwpck_require__ ( 186 ) ) ;
5843- const github = __importStar ( __nccwpck_require__ ( 438 ) ) ;
5844- if ( ! github ) {
5845- throw new Error ( 'Module not found: github' ) ;
5846- }
5847- if ( ! core ) {
5848- throw new Error ( 'Module not found: core' ) ;
5849- }
5850- async function main ( ) {
5851- const { eventName, sha, ref, repo : { owner, repo } , payload, } = github . context ;
5852- const { GITHUB_RUN_ID } = process . env ;
5853- let branch = ref . slice ( 11 ) ;
5854- let headSha = sha ;
5855- if ( payload . pull_request ) {
5856- branch = payload . pull_request . head . ref ;
5857- headSha = payload . pull_request . head . sha ;
5858- }
5859- else if ( payload . workflow_run ) {
5860- branch = payload . workflow_run . head_branch ;
5861- headSha = payload . workflow_run . head_sha ;
5862- }
5863- console . log ( { eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID } ) ;
5864- const token = core . getInput ( 'access_token' , { required : true } ) ;
5865- const workflow_id = core . getInput ( 'workflow_id' , { required : false } ) ;
5866- const ignore_sha = core . getInput ( 'ignore_sha' , { required : false } ) === 'true' ;
5867- const all_but_latest = core . getInput ( 'all_but_latest' , { required : false } ) ;
5868- console . log ( `Found token: ${ token ? 'yes' : 'no' } ` ) ;
5869- const workflow_ids = [ ] ;
5870- const octokit = github . getOctokit ( token ) ;
5871- const { data : current_run } = await octokit . actions . getWorkflowRun ( {
5872- owner,
5873- repo,
5874- run_id : Number ( GITHUB_RUN_ID ) ,
5875- } ) ;
5876- if ( workflow_id ) {
5877- workflow_id
5878- . replace ( / \s / g, '' )
5879- . split ( ',' )
5880- . forEach ( n => workflow_ids . push ( n ) ) ;
5881- }
5882- else {
5883- workflow_ids . push ( String ( current_run . workflow_id ) ) ;
5884- }
5885- console . log ( `Found workflow_id: ${ JSON . stringify ( workflow_ids ) } ` ) ;
5886- await Promise . all ( workflow_ids . map ( async ( workflow_id ) => {
5887- try {
5888- const { data : { total_count, workflow_runs } , } = await octokit . actions . listWorkflowRuns ( {
5889- per_page : 100 ,
5890- owner,
5891- repo,
5892- workflow_id,
5893- branch,
5894- } ) ;
5895- console . log ( `Found ${ total_count } runs total.` ) ;
5896- let cancelBefore = new Date ( current_run . created_at ) ;
5897- if ( all_but_latest ) {
5898- const n = workflow_runs
5899- . map ( run => new Date ( run . created_at ) . getTime ( ) )
5900- . reduce ( ( a , b ) => Math . max ( a , b ) , cancelBefore . getTime ( ) ) ;
5901- cancelBefore = new Date ( n ) ;
5902- }
5903- const runningWorkflows = workflow_runs . filter ( run => run . id !== current_run . id &&
5904- ( ignore_sha || run . head_sha !== headSha ) &&
5905- run . status !== 'completed' &&
5906- new Date ( run . created_at ) < cancelBefore ) ;
5907- if ( all_but_latest && new Date ( current_run . created_at ) < cancelBefore ) {
5908- runningWorkflows . push ( current_run ) ;
5909- }
5910- console . log ( `Found ${ runningWorkflows . length } runs to cancel.` ) ;
5911- for ( const { id, head_sha, status, html_url } of runningWorkflows ) {
5912- console . log ( 'Canceling run: ' , { id, head_sha, status, html_url } ) ;
5913- const res = await octokit . actions . cancelWorkflowRun ( {
5914- owner,
5915- repo,
5916- run_id : id ,
5917- } ) ;
5918- console . log ( `Cancel run ${ id } responded with status ${ res . status } ` ) ;
5919- }
5920- }
5921- catch ( e ) {
5922- const msg = e . message || e ;
5923- console . log ( `Error while canceling workflow_id ${ workflow_id } : ${ msg } ` ) ;
5924- }
5925- console . log ( '' ) ;
5926- } ) ) ;
5927- }
5928- main ( )
5929- . then ( ( ) => core . info ( 'Cancel Complete.' ) )
5930- . catch ( e => core . setFailed ( e . message ) ) ;
5931-
5932-
59335814/***/ } ) ,
59345815
59355816/***/ 877 :
@@ -6052,8 +5933,9 @@ module.exports = require("zlib");;
60525933/******/ // The require function
60535934/******/ function __nccwpck_require__ ( moduleId ) {
60545935/******/ // Check if module is in cache
6055- /******/ if ( __webpack_module_cache__ [ moduleId ] ) {
6056- /******/ return __webpack_module_cache__ [ moduleId ] . exports ;
5936+ /******/ var cachedModule = __webpack_module_cache__ [ moduleId ] ;
5937+ /******/ if ( cachedModule !== undefined ) {
5938+ /******/ return cachedModule . exports ;
60575939/******/ }
60585940/******/ // Create a new module (and put it into the cache)
60595941/******/ var module = __webpack_module_cache__ [ moduleId ] = {
@@ -6076,12 +5958,150 @@ module.exports = require("zlib");;
60765958/******/ }
60775959/******/
60785960/************************************************************************/
5961+ /******/ /* webpack/runtime/compat get default export */
5962+ /******/ ( ( ) => {
5963+ /******/ // getDefaultExport function for compatibility with non-harmony modules
5964+ /******/ __nccwpck_require__ . n = ( module ) => {
5965+ /******/ var getter = module && module . __esModule ?
5966+ /******/ ( ) => ( module [ 'default' ] ) :
5967+ /******/ ( ) => ( module ) ;
5968+ /******/ __nccwpck_require__ . d ( getter , { a : getter } ) ;
5969+ /******/ return getter ;
5970+ /******/ } ;
5971+ /******/ } ) ( ) ;
5972+ /******/
5973+ /******/ /* webpack/runtime/define property getters */
5974+ /******/ ( ( ) => {
5975+ /******/ // define getter functions for harmony exports
5976+ /******/ __nccwpck_require__ . d = ( exports , definition ) => {
5977+ /******/ for ( var key in definition ) {
5978+ /******/ if ( __nccwpck_require__ . o ( definition , key ) && ! __nccwpck_require__ . o ( exports , key ) ) {
5979+ /******/ Object . defineProperty ( exports , key , { enumerable : true , get : definition [ key ] } ) ;
5980+ /******/ }
5981+ /******/ }
5982+ /******/ } ;
5983+ /******/ } ) ( ) ;
5984+ /******/
5985+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
5986+ /******/ ( ( ) => {
5987+ /******/ __nccwpck_require__ . o = ( obj , prop ) => ( Object . prototype . hasOwnProperty . call ( obj , prop ) )
5988+ /******/ } ) ( ) ;
5989+ /******/
5990+ /******/ /* webpack/runtime/make namespace object */
5991+ /******/ ( ( ) => {
5992+ /******/ // define __esModule on exports
5993+ /******/ __nccwpck_require__ . r = ( exports ) => {
5994+ /******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
5995+ /******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
5996+ /******/ }
5997+ /******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
5998+ /******/ } ;
5999+ /******/ } ) ( ) ;
6000+ /******/
60796001/******/ /* webpack/runtime/compat */
60806002/******/
6081- /******/ __nccwpck_require__ . ab = __dirname + "/" ; /************************************************************************/
6082- /******/ // module exports must be returned from runtime so entry inlining is disabled
6083- /******/ // startup
6084- /******/ // Load entry module and return exports
6085- /******/ return __nccwpck_require__ ( 144 ) ;
6003+ /******/ if ( typeof __nccwpck_require__ !== 'undefined' ) __nccwpck_require__ . ab = __dirname + "/" ; /************************************************************************/
6004+ var __webpack_exports__ = { } ;
6005+ // This entry need to be wrapped in an IIFE because it need to be in strict mode.
6006+ ( ( ) => {
6007+ "use strict" ;
6008+ __nccwpck_require__ . r ( __webpack_exports__ ) ;
6009+ /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__ ( 186 ) ;
6010+ /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/ __nccwpck_require__ . n ( _actions_core__WEBPACK_IMPORTED_MODULE_0__ ) ;
6011+ /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__ ( 438 ) ;
6012+ /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/ __nccwpck_require__ . n ( _actions_github__WEBPACK_IMPORTED_MODULE_1__ ) ;
6013+
6014+
6015+ if ( ! _actions_github__WEBPACK_IMPORTED_MODULE_1__ ) {
6016+ throw new Error ( 'Module not found: github' ) ;
6017+ }
6018+ if ( ! _actions_core__WEBPACK_IMPORTED_MODULE_0__ ) {
6019+ throw new Error ( 'Module not found: core' ) ;
6020+ }
6021+ async function main ( ) {
6022+ const { eventName, sha, ref, repo : { owner, repo } , payload, } = _actions_github__WEBPACK_IMPORTED_MODULE_1__ . context ;
6023+ const { GITHUB_RUN_ID } = process . env ;
6024+ let branch = ref . slice ( 11 ) ;
6025+ let headSha = sha ;
6026+ if ( payload . pull_request ) {
6027+ branch = payload . pull_request . head . ref ;
6028+ headSha = payload . pull_request . head . sha ;
6029+ }
6030+ else if ( payload . workflow_run ) {
6031+ branch = payload . workflow_run . head_branch ;
6032+ headSha = payload . workflow_run . head_sha ;
6033+ }
6034+ console . log ( { eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID } ) ;
6035+ const token = _actions_core__WEBPACK_IMPORTED_MODULE_0__ . getInput ( 'access_token' , { required : true } ) ;
6036+ const workflow_id = _actions_core__WEBPACK_IMPORTED_MODULE_0__ . getInput ( 'workflow_id' , { required : false } ) ;
6037+ const ignore_sha = _actions_core__WEBPACK_IMPORTED_MODULE_0__ . getInput ( 'ignore_sha' , { required : false } ) === 'true' ;
6038+ const all_but_latest = _actions_core__WEBPACK_IMPORTED_MODULE_0__ . getInput ( 'all_but_latest' , { required : false } ) ;
6039+ console . log ( `Found token: ${ token ? 'yes' : 'no' } ` ) ;
6040+ const workflow_ids = [ ] ;
6041+ const octokit = _actions_github__WEBPACK_IMPORTED_MODULE_1__ . getOctokit ( token ) ;
6042+ const { data : current_run } = await octokit . actions . getWorkflowRun ( {
6043+ owner,
6044+ repo,
6045+ run_id : Number ( GITHUB_RUN_ID ) ,
6046+ } ) ;
6047+ if ( workflow_id ) {
6048+ workflow_id
6049+ . replace ( / \s / g, '' )
6050+ . split ( ',' )
6051+ . forEach ( n => workflow_ids . push ( n ) ) ;
6052+ }
6053+ else {
6054+ workflow_ids . push ( String ( current_run . workflow_id ) ) ;
6055+ }
6056+ console . log ( `Found workflow_id: ${ JSON . stringify ( workflow_ids ) } ` ) ;
6057+ await Promise . all ( workflow_ids . map ( async ( workflow_id ) => {
6058+ try {
6059+ const { data : { total_count, workflow_runs } , } = await octokit . actions . listWorkflowRuns ( {
6060+ per_page : 100 ,
6061+ owner,
6062+ repo,
6063+ workflow_id,
6064+ branch,
6065+ } ) ;
6066+ console . log ( `Found ${ total_count } runs total.` ) ;
6067+ let cancelBefore = new Date ( current_run . created_at ) ;
6068+ if ( all_but_latest ) {
6069+ const n = workflow_runs
6070+ . map ( run => new Date ( run . created_at ) . getTime ( ) )
6071+ . reduce ( ( a , b ) => Math . max ( a , b ) , cancelBefore . getTime ( ) ) ;
6072+ cancelBefore = new Date ( n ) ;
6073+ }
6074+ const runningWorkflows = workflow_runs . filter ( run => run . id !== current_run . id &&
6075+ ( ignore_sha || run . head_sha !== headSha ) &&
6076+ run . status !== 'completed' &&
6077+ new Date ( run . created_at ) < cancelBefore ) ;
6078+ if ( all_but_latest && new Date ( current_run . created_at ) < cancelBefore ) {
6079+ runningWorkflows . push ( current_run ) ;
6080+ }
6081+ console . log ( `Found ${ runningWorkflows . length } runs to cancel.` ) ;
6082+ for ( const { id, head_sha, status, html_url } of runningWorkflows ) {
6083+ console . log ( 'Canceling run: ' , { id, head_sha, status, html_url } ) ;
6084+ const res = await octokit . actions . cancelWorkflowRun ( {
6085+ owner,
6086+ repo,
6087+ run_id : id ,
6088+ } ) ;
6089+ console . log ( `Cancel run ${ id } responded with status ${ res . status } ` ) ;
6090+ }
6091+ }
6092+ catch ( e ) {
6093+ const msg = e . message || e ;
6094+ console . log ( `Error while canceling workflow_id ${ workflow_id } : ${ msg } ` ) ;
6095+ }
6096+ console . log ( '' ) ;
6097+ } ) ) ;
6098+ }
6099+ main ( )
6100+ . then ( ( ) => _actions_core__WEBPACK_IMPORTED_MODULE_0__ . info ( 'Cancel Complete.' ) )
6101+ . catch ( e => _actions_core__WEBPACK_IMPORTED_MODULE_0__ . setFailed ( e . message ) ) ;
6102+
6103+ } ) ( ) ;
6104+
6105+ module . exports = __webpack_exports__ ;
60866106/******/ } ) ( )
60876107;
0 commit comments