From 953e057dc81d3458935a18d1184c386b0f6b5738 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Sun, 1 Nov 2020 21:00:39 +0100 Subject: [PATCH] Fix case of running cancel for different workflow During 4.3 the case with different workflow was broken. This is a fix to this problem. --- dist/index.js | 61 +++++++++++++++++++++++++++++---------------------- src/main.ts | 49 ++++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 36 deletions(-) diff --git a/dist/index.js b/dist/index.js index e6422c4..4afd5db 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1491,10 +1491,11 @@ var CancelMode; * Converts the source of a run object into a string that can be used as map key in maps where we keep * arrays of runs per source group * @param triggeringRunInfo the object identifying the triggering workflow + * @param sourceWorkflowId - workflow id to act on * @returns the unique string id for the group */ -function getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo) { - return (`:${triggeringRunInfo.workflowId}:${triggeringRunInfo.headRepo}` + +function getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo, sourceWorkflowId) { + return (`:${sourceWorkflowId}:${triggeringRunInfo.headRepo}` + `:${triggeringRunInfo.headBranch}:${triggeringRunInfo.eventName}`); } /** @@ -1513,14 +1514,15 @@ function getCommonGroupIdFromRunItem(runItem) { * @param repositoryInfo - information about the repository used * @param status - status of the run that we are querying for * @param triggeringRunInfo - information about the workflow that triggered the run + * @param sourceWorkflowId - workflow id to act on * @return query parameters merged with the listWorkflowRuns criteria */ -function createListRunsQueryRunsSameSource(repositoryInfo, status, triggeringRunInfo) { +function createListRunsQueryRunsSameSource(repositoryInfo, sourceWorkflowId, status, triggeringRunInfo) { const request = { owner: repositoryInfo.owner, repo: repositoryInfo.repo, // eslint-disable-next-line @typescript-eslint/camelcase - workflow_id: triggeringRunInfo.workflowId, + workflow_id: sourceWorkflowId, status, branch: triggeringRunInfo.headBranch, event: triggeringRunInfo.eventName @@ -1530,16 +1532,17 @@ function createListRunsQueryRunsSameSource(repositoryInfo, status, triggeringRun /** * Creates query parameters selecting only specific run Id. * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param status - status of the run that we are querying for * @param triggeringRunInfo - information about the workflow that triggered the run * @return query parameters merged with the listWorkflowRuns criteria */ -function createListRunsQuerySpecificRunId(repositoryInfo, status, triggeringRunInfo) { +function createListRunsQuerySpecificRunId(repositoryInfo, sourceWorkflowId, status, triggeringRunInfo) { const request = { owner: repositoryInfo.owner, repo: repositoryInfo.repo, // eslint-disable-next-line @typescript-eslint/camelcase - workflow_id: triggeringRunInfo.workflowId, + workflow_id: sourceWorkflowId, status, // eslint-disable-next-line @typescript-eslint/camelcase run_id: triggeringRunInfo.runId.toString() @@ -1747,10 +1750,11 @@ function getWorkflowRuns(repositoryInfo, statusValues, cancelMode, createListRun * @param runItem item to check * @param cancelFutureDuplicates whether future duplicates are being cancelled * @param triggeringRunInfo - information about the workflow that triggered the run + * @param sourceWorkflowId - workflow id to act on * @param mapOfWorkflowRunCandidates - map of the workflow runs to add candidates to * @return true if we determine that the run Id should be cancelled */ -function checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, triggeringRunInfo, mapOfWorkflowRunCandidates) { +function checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, triggeringRunInfo, sourceWorkflowId, mapOfWorkflowRunCandidates) { const runHeadRepo = runItem.head_repository.full_name; if (triggeringRunInfo.headRepo !== undefined && runHeadRepo !== triggeringRunInfo.headRepo) { @@ -1759,7 +1763,7 @@ function checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, t } if (cancelFutureDuplicates) { core.info(`\nCancel Future Duplicates: Returning run id that might be duplicate or my own run: ${runItem.id}.\n`); - addWorkflowRunToMap(getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo), runItem, mapOfWorkflowRunCandidates); + addWorkflowRunToMap(getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo, sourceWorkflowId), runItem, mapOfWorkflowRunCandidates); } else { if (runItem.id === triggeringRunInfo.runId) { @@ -1860,6 +1864,7 @@ function checkCandidateForDuplicateNamedJobs(repositoryInfo, runItem, jobNamesRe * Determines whether the run is candidate to be cancelled depending on the mode used and add it to the map * of workflow names if it is. * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param runItem - run item * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode @@ -1868,7 +1873,7 @@ function checkCandidateForDuplicateNamedJobs(repositoryInfo, runItem, jobNamesRe * @param skipEventTypes - which events should be skipped * @param mapOfWorkflowRunCandidates - map of workflow runs to add candidates to */ -function checkCandidateForCancelling(repositoryInfo, runItem, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNamesRegexps, skipEventTypes, mapOfWorkflowRunCandidates) { +function checkCandidateForCancelling(repositoryInfo, sourceWorkflowId, runItem, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNamesRegexps, skipEventTypes, mapOfWorkflowRunCandidates) { return __awaiter(this, void 0, void 0, function* () { if ('completed' === runItem.status.toString()) { core.info(`\nThe run ${runItem.id} is completed. Not adding as candidate to cancel.\n`); @@ -1894,7 +1899,7 @@ function checkCandidateForCancelling(repositoryInfo, runItem, triggeringRunInfo, checkCandidateForCancellingSelf(runItem, triggeringRunInfo, mapOfWorkflowRunCandidates); } else if (cancelMode === CancelMode.DUPLICATES) { - checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, triggeringRunInfo, mapOfWorkflowRunCandidates); + checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, triggeringRunInfo, sourceWorkflowId, mapOfWorkflowRunCandidates); } else if (cancelMode === CancelMode.ALL_DUPLICATES) { checkCandidateForAllDuplicates(runItem, triggeringRunInfo, mapOfWorkflowRunCandidates); @@ -1933,34 +1938,35 @@ function cancelRun(repositoryInfo, runId) { /** * Returns map of workflow run items matching the criteria specified group by workflow run id * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param statusValues - status values we want to check * @param cancelMode - cancel mode to use * @param triggeringRunInfo - information about the workflow that triggered the run * @return map of the run items matching grouped by workflow run id */ -function getWorkflowRunsMatchingCriteria(repositoryInfo, statusValues, cancelMode, triggeringRunInfo) { +function getWorkflowRunsMatchingCriteria(repositoryInfo, sourceWorkflowId, statusValues, cancelMode, triggeringRunInfo) { return __awaiter(this, void 0, void 0, function* () { return yield getWorkflowRuns(repositoryInfo, statusValues, cancelMode, function (status) { if (cancelMode === CancelMode.SELF) { core.info(`\nFinding runs for my own run: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Workflow ID:${triggeringRunInfo.workflowId},` + + `Workflow ID:${sourceWorkflowId},` + `Source Run id: ${triggeringRunInfo.runId}\n`); - return createListRunsQuerySpecificRunId(repositoryInfo, status, triggeringRunInfo); + return createListRunsQuerySpecificRunId(repositoryInfo, sourceWorkflowId, status, triggeringRunInfo); } else if (cancelMode === CancelMode.FAILED_JOBS || cancelMode === CancelMode.NAMED_JOBS || cancelMode === CancelMode.ALL_DUPLICATES || cancelMode === CancelMode.ALL_DUPLICATED_NAMED_JOBS) { core.info(`\nFinding runs for all runs: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Status: ${status} Workflow ID:${triggeringRunInfo.workflowId}\n`); - return createListRunsQueryAllRuns(repositoryInfo, status, triggeringRunInfo.workflowId); + `Status: ${status} Workflow ID:${sourceWorkflowId}\n`); + return createListRunsQueryAllRuns(repositoryInfo, status, sourceWorkflowId); } else if (cancelMode === CancelMode.DUPLICATES) { core.info(`\nFinding duplicate runs: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Status: ${status} Workflow ID:${triggeringRunInfo.workflowId}, ` + + `Status: ${status} Workflow ID:${sourceWorkflowId}, ` + `Head Branch: ${triggeringRunInfo.headBranch},` + `Event name: ${triggeringRunInfo.eventName}\n`); - return createListRunsQueryRunsSameSource(repositoryInfo, status, triggeringRunInfo); + return createListRunsQueryRunsSameSource(repositoryInfo, sourceWorkflowId, status, triggeringRunInfo); } else { throw Error(`\nWrong cancel mode ${cancelMode}! Please correct it.\n`); @@ -2017,6 +2023,7 @@ function findPullRequestForRunItem(repositoryInfo, runItem) { * same group are put together in one array - in a map indexed by the source group id. * * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode to use * @param cancelFutureDuplicates - whether to cancel future duplicates @@ -2029,7 +2036,7 @@ function findPullRequestForRunItem(repositoryInfo, runItem) { * * source group id (allDuplicates mode) * * matching job name (allDuplicatedMatchingJobNames mode) */ -function filterAndMapWorkflowRunsToGroups(repositoryInfo, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, selfRunId, selfPreservation, workflowRuns) { +function filterAndMapWorkflowRunsToGroups(repositoryInfo, sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, selfRunId, selfPreservation, workflowRuns) { return __awaiter(this, void 0, void 0, function* () { const mapOfWorkflowRunCandidates = new Map(); for (const [key, runItem] of workflowRuns) { @@ -2039,7 +2046,7 @@ function filterAndMapWorkflowRunsToGroups(repositoryInfo, triggeringRunInfo, can core.info(`\nI have self-preservation built in. I refuse to cancel myself :)\n`); continue; } - yield checkCandidateForCancelling(repositoryInfo, runItem, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, mapOfWorkflowRunCandidates); + yield checkCandidateForCancelling(repositoryInfo, sourceWorkflowId, runItem, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, mapOfWorkflowRunCandidates); } return mapOfWorkflowRunCandidates; }); @@ -2150,6 +2157,7 @@ function cancelTheRunsPerGroup(repositoryInfo, mapOfWorkflowRunCandidatesCandida * Find and cancels runs based on the criteria chosen. * @param repositoryInfo - information about the repository used * @param selfRunId - number of own run id + * @param sourceWorkflowId - workflow id to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode used * @param cancelFutureDuplicates - whether to cancel future duplicates for duplicate cancelling @@ -2161,11 +2169,11 @@ function cancelTheRunsPerGroup(repositoryInfo, mapOfWorkflowRunCandidatesCandida * @param selfPreservation - whether the run will cancel itself if requested * @return array of canceled workflow run ids */ -function findAndCancelRuns(repositoryInfo, selfRunId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, notifyPRCancel, notifyPRMessageStart, jobNameRegexps, skipEventTypes, reason, selfPreservation) { +function findAndCancelRuns(repositoryInfo, selfRunId, sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, notifyPRCancel, notifyPRMessageStart, jobNameRegexps, skipEventTypes, reason, selfPreservation) { return __awaiter(this, void 0, void 0, function* () { const statusValues = ['queued', 'in_progress']; - const workflowRuns = yield getWorkflowRunsMatchingCriteria(repositoryInfo, statusValues, cancelMode, triggeringRunInfo); - const mapOfWorkflowRunCandidatesCandidatesToCancel = yield filterAndMapWorkflowRunsToGroups(repositoryInfo, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, selfRunId, selfPreservation, workflowRuns); + const workflowRuns = yield getWorkflowRunsMatchingCriteria(repositoryInfo, sourceWorkflowId, statusValues, cancelMode, triggeringRunInfo); + const mapOfWorkflowRunCandidatesCandidatesToCancel = yield filterAndMapWorkflowRunsToGroups(repositoryInfo, sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, jobNameRegexps, skipEventTypes, selfRunId, selfPreservation, workflowRuns); return yield cancelTheRunsPerGroup(repositoryInfo, mapOfWorkflowRunCandidatesCandidatesToCancel, cancelMode, cancelFutureDuplicates, notifyPRCancel, selfRunId, reason); }); } @@ -2221,6 +2229,7 @@ function getTriggeringRunInfo(repositoryInfo, runId) { * * @param repositoryInfo - information about the repository used * @param selfRunId - number of own run id + * @param sourceWorkflowId - id of the workflow to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode used * @param notifyPRCancel - whether to notify in PRs about cancelling @@ -2232,11 +2241,11 @@ function getTriggeringRunInfo(repositoryInfo, runId) { * @param cancelFutureDuplicates - whether to cancel future duplicates for duplicate cancelling * @param selfPreservation - whether the run will cancel itself if requested */ -function performCancelJob(repositoryInfo, selfRunId, triggeringRunInfo, cancelMode, notifyPRCancel, notifyPRCancelMessage, notifyPRMessageStart, jobNameRegexps, skipEventTypes, cancelFutureDuplicates, selfPreservation) { +function performCancelJob(repositoryInfo, selfRunId, sourceWorkflowId, triggeringRunInfo, cancelMode, notifyPRCancel, notifyPRCancelMessage, notifyPRMessageStart, jobNameRegexps, skipEventTypes, cancelFutureDuplicates, selfPreservation) { return __awaiter(this, void 0, void 0, function* () { core.info('\n###################################################################################\n'); core.info(`All parameters: owner: ${repositoryInfo.owner}, repo: ${repositoryInfo.repo}, ` + - `run id: ${triggeringRunInfo.runId}, ` + + `run id: ${triggeringRunInfo.runId}, Source workflow id: ${sourceWorkflowId}, ` + `head repo ${triggeringRunInfo.headRepo}, headBranch: ${triggeringRunInfo.headBranch}, ` + `sourceEventName: ${triggeringRunInfo.eventName}, ` + `cancelMode: ${cancelMode}, jobNames: ${jobNameRegexps}`); @@ -2276,7 +2285,7 @@ function performCancelJob(repositoryInfo, selfRunId, triggeringRunInfo, cancelMo throw Error(`Wrong cancel mode ${cancelMode}! Please correct it.`); } core.info('\n###################################################################################\n'); - return yield findAndCancelRuns(repositoryInfo, selfRunId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, notifyPRCancel, notifyPRMessageStart, jobNameRegexps, skipEventTypes, reason, selfPreservation); + return yield findAndCancelRuns(repositoryInfo, selfRunId, sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, notifyPRCancel, notifyPRMessageStart, jobNameRegexps, skipEventTypes, reason, selfPreservation); }); } /** @@ -2445,7 +2454,7 @@ function run() { const triggeringRunInfo = yield getTriggeringRunInfo(repositoryInfo, sourceRunId); produceBasicOutputs(triggeringRunInfo); yield notifyActionStart(repositoryInfo, triggeringRunInfo, selfRunId, notifyPRMessageStart); - const cancelledRuns = yield performCancelJob(repositoryInfo, selfRunId, triggeringRunInfo, cancelMode, notifyPRCancel, notifyPRCancelMessage, notifyPRMessageStart, jobNameRegexps, skipEventTypes, cancelFutureDuplicates, selfPreservation); + const cancelledRuns = yield performCancelJob(repositoryInfo, selfRunId, sourceWorkflowId, triggeringRunInfo, cancelMode, notifyPRCancel, notifyPRCancelMessage, notifyPRMessageStart, jobNameRegexps, skipEventTypes, cancelFutureDuplicates, selfPreservation); verboseOutput('cancelledRuns', JSON.stringify(cancelledRuns)); }); } diff --git a/src/main.ts b/src/main.ts index cd99a35..109dd86 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,13 +53,15 @@ interface TriggeringRunInfo { * Converts the source of a run object into a string that can be used as map key in maps where we keep * arrays of runs per source group * @param triggeringRunInfo the object identifying the triggering workflow + * @param sourceWorkflowId - workflow id to act on * @returns the unique string id for the group */ function getCommonGroupIdFromTriggeringRunInfo( - triggeringRunInfo: TriggeringRunInfo + triggeringRunInfo: TriggeringRunInfo, + sourceWorkflowId: string | number ): string { return ( - `:${triggeringRunInfo.workflowId}:${triggeringRunInfo.headRepo}` + + `:${sourceWorkflowId}:${triggeringRunInfo.headRepo}` + `:${triggeringRunInfo.headBranch}:${triggeringRunInfo.eventName}` ) } @@ -85,10 +87,12 @@ function getCommonGroupIdFromRunItem( * @param repositoryInfo - information about the repository used * @param status - status of the run that we are querying for * @param triggeringRunInfo - information about the workflow that triggered the run + * @param sourceWorkflowId - workflow id to act on * @return query parameters merged with the listWorkflowRuns criteria */ function createListRunsQueryRunsSameSource( repositoryInfo: RepositoryInfo, + sourceWorkflowId: string | number, status: string, triggeringRunInfo: TriggeringRunInfo ): rest.RequestOptions { @@ -96,7 +100,7 @@ function createListRunsQueryRunsSameSource( owner: repositoryInfo.owner, repo: repositoryInfo.repo, // eslint-disable-next-line @typescript-eslint/camelcase - workflow_id: triggeringRunInfo.workflowId, + workflow_id: sourceWorkflowId, status, branch: triggeringRunInfo.headBranch, event: triggeringRunInfo.eventName @@ -106,12 +110,14 @@ function createListRunsQueryRunsSameSource( /** * Creates query parameters selecting only specific run Id. * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param status - status of the run that we are querying for * @param triggeringRunInfo - information about the workflow that triggered the run * @return query parameters merged with the listWorkflowRuns criteria */ function createListRunsQuerySpecificRunId( repositoryInfo: RepositoryInfo, + sourceWorkflowId: string | number, status: string, triggeringRunInfo: TriggeringRunInfo ): rest.RequestOptions { @@ -119,7 +125,7 @@ function createListRunsQuerySpecificRunId( owner: repositoryInfo.owner, repo: repositoryInfo.repo, // eslint-disable-next-line @typescript-eslint/camelcase - workflow_id: triggeringRunInfo.workflowId, + workflow_id: sourceWorkflowId, status, // eslint-disable-next-line @typescript-eslint/camelcase run_id: triggeringRunInfo.runId.toString() @@ -353,6 +359,7 @@ async function getWorkflowRuns( * @param runItem item to check * @param cancelFutureDuplicates whether future duplicates are being cancelled * @param triggeringRunInfo - information about the workflow that triggered the run + * @param sourceWorkflowId - workflow id to act on * @param mapOfWorkflowRunCandidates - map of the workflow runs to add candidates to * @return true if we determine that the run Id should be cancelled */ @@ -360,6 +367,7 @@ function checkCandidateForCancellingDuplicate( runItem: rest.ActionsListWorkflowRunsResponseWorkflowRunsItem, cancelFutureDuplicates: boolean, triggeringRunInfo: TriggeringRunInfo, + sourceWorkflowId: string | number, mapOfWorkflowRunCandidates: Map< string, rest.ActionsListWorkflowRunsResponseWorkflowRunsItem[] @@ -380,7 +388,10 @@ function checkCandidateForCancellingDuplicate( `\nCancel Future Duplicates: Returning run id that might be duplicate or my own run: ${runItem.id}.\n` ) addWorkflowRunToMap( - getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo), + getCommonGroupIdFromTriggeringRunInfo( + triggeringRunInfo, + sourceWorkflowId + ), runItem, mapOfWorkflowRunCandidates ) @@ -551,6 +562,7 @@ async function checkCandidateForDuplicateNamedJobs( * Determines whether the run is candidate to be cancelled depending on the mode used and add it to the map * of workflow names if it is. * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param runItem - run item * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode @@ -561,6 +573,7 @@ async function checkCandidateForDuplicateNamedJobs( */ async function checkCandidateForCancelling( repositoryInfo: RepositoryInfo, + sourceWorkflowId: string | number, runItem: rest.ActionsListWorkflowRunsResponseWorkflowRunsItem, triggeringRunInfo: TriggeringRunInfo, cancelMode: CancelMode, @@ -619,6 +632,7 @@ async function checkCandidateForCancelling( runItem, cancelFutureDuplicates, triggeringRunInfo, + sourceWorkflowId, mapOfWorkflowRunCandidates ) } else if (cancelMode === CancelMode.ALL_DUPLICATES) { @@ -668,6 +682,7 @@ async function cancelRun( /** * Returns map of workflow run items matching the criteria specified group by workflow run id * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param statusValues - status values we want to check * @param cancelMode - cancel mode to use * @param triggeringRunInfo - information about the workflow that triggered the run @@ -675,6 +690,7 @@ async function cancelRun( */ async function getWorkflowRunsMatchingCriteria( repositoryInfo: RepositoryInfo, + sourceWorkflowId: string | number, statusValues: string[], cancelMode: CancelMode, triggeringRunInfo: TriggeringRunInfo @@ -687,11 +703,12 @@ async function getWorkflowRunsMatchingCriteria( if (cancelMode === CancelMode.SELF) { core.info( `\nFinding runs for my own run: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Workflow ID:${triggeringRunInfo.workflowId},` + + `Workflow ID:${sourceWorkflowId},` + `Source Run id: ${triggeringRunInfo.runId}\n` ) return createListRunsQuerySpecificRunId( repositoryInfo, + sourceWorkflowId, status, triggeringRunInfo ) @@ -703,22 +720,23 @@ async function getWorkflowRunsMatchingCriteria( ) { core.info( `\nFinding runs for all runs: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Status: ${status} Workflow ID:${triggeringRunInfo.workflowId}\n` + `Status: ${status} Workflow ID:${sourceWorkflowId}\n` ) return createListRunsQueryAllRuns( repositoryInfo, status, - triggeringRunInfo.workflowId + sourceWorkflowId ) } else if (cancelMode === CancelMode.DUPLICATES) { core.info( `\nFinding duplicate runs: Owner: ${repositoryInfo.owner}, Repo: ${repositoryInfo.repo}, ` + - `Status: ${status} Workflow ID:${triggeringRunInfo.workflowId}, ` + + `Status: ${status} Workflow ID:${sourceWorkflowId}, ` + `Head Branch: ${triggeringRunInfo.headBranch},` + `Event name: ${triggeringRunInfo.eventName}\n` ) return createListRunsQueryRunsSameSource( repositoryInfo, + sourceWorkflowId, status, triggeringRunInfo ) @@ -793,6 +811,7 @@ async function findPullRequestForRunItem( * same group are put together in one array - in a map indexed by the source group id. * * @param repositoryInfo - information about the repository used + * @param sourceWorkflowId - workflow id to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode to use * @param cancelFutureDuplicates - whether to cancel future duplicates @@ -807,6 +826,7 @@ async function findPullRequestForRunItem( */ async function filterAndMapWorkflowRunsToGroups( repositoryInfo: RepositoryInfo, + sourceWorkflowId: string | number, triggeringRunInfo: TriggeringRunInfo, cancelMode: CancelMode, cancelFutureDuplicates: boolean, @@ -835,6 +855,7 @@ async function filterAndMapWorkflowRunsToGroups( } await checkCandidateForCancelling( repositoryInfo, + sourceWorkflowId, runItem, triggeringRunInfo, cancelMode, @@ -1009,6 +1030,7 @@ async function cancelTheRunsPerGroup( * Find and cancels runs based on the criteria chosen. * @param repositoryInfo - information about the repository used * @param selfRunId - number of own run id + * @param sourceWorkflowId - workflow id to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode used * @param cancelFutureDuplicates - whether to cancel future duplicates for duplicate cancelling @@ -1023,6 +1045,7 @@ async function cancelTheRunsPerGroup( async function findAndCancelRuns( repositoryInfo: RepositoryInfo, selfRunId: number, + sourceWorkflowId: string | number, triggeringRunInfo: TriggeringRunInfo, cancelMode: CancelMode, cancelFutureDuplicates: boolean, @@ -1036,12 +1059,14 @@ async function findAndCancelRuns( const statusValues = ['queued', 'in_progress'] const workflowRuns = await getWorkflowRunsMatchingCriteria( repositoryInfo, + sourceWorkflowId, statusValues, cancelMode, triggeringRunInfo ) const mapOfWorkflowRunCandidatesCandidatesToCancel = await filterAndMapWorkflowRunsToGroups( repositoryInfo, + sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, @@ -1125,6 +1150,7 @@ async function getTriggeringRunInfo( * * @param repositoryInfo - information about the repository used * @param selfRunId - number of own run id + * @param sourceWorkflowId - id of the workflow to act on * @param triggeringRunInfo - information about the workflow that triggered the run * @param cancelMode - cancel mode used * @param notifyPRCancel - whether to notify in PRs about cancelling @@ -1139,6 +1165,7 @@ async function getTriggeringRunInfo( async function performCancelJob( repositoryInfo: RepositoryInfo, selfRunId: number, + sourceWorkflowId: string | number, triggeringRunInfo: TriggeringRunInfo, cancelMode: CancelMode, notifyPRCancel: boolean, @@ -1154,7 +1181,7 @@ async function performCancelJob( ) core.info( `All parameters: owner: ${repositoryInfo.owner}, repo: ${repositoryInfo.repo}, ` + - `run id: ${triggeringRunInfo.runId}, ` + + `run id: ${triggeringRunInfo.runId}, Source workflow id: ${sourceWorkflowId}, ` + `head repo ${triggeringRunInfo.headRepo}, headBranch: ${triggeringRunInfo.headBranch}, ` + `sourceEventName: ${triggeringRunInfo.eventName}, ` + `cancelMode: ${cancelMode}, jobNames: ${jobNameRegexps}` @@ -1209,6 +1236,7 @@ async function performCancelJob( return await findAndCancelRuns( repositoryInfo, selfRunId, + sourceWorkflowId, triggeringRunInfo, cancelMode, cancelFutureDuplicates, @@ -1469,6 +1497,7 @@ async function run(): Promise { const cancelledRuns = await performCancelJob( repositoryInfo, selfRunId, + sourceWorkflowId, triggeringRunInfo, cancelMode, notifyPRCancel,