From a66ae1f29f50777b386e60b6bc1abeae8a8462a5 Mon Sep 17 00:00:00 2001 From: spaceface Date: Thu, 29 Jul 2021 22:53:47 +0200 Subject: [PATCH] fix cancelling jobs from different repos where two branches have the same name (#105) Co-authored-by: Steven --- dist/index.js | 4 +++- src/index.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 3056d027..3f613e47 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6122,6 +6122,7 @@ async function main() { workflow_ids.push(String(current_run.workflow_id)); } console.log(`Found workflow_id: ${JSON.stringify(workflow_ids)}`); + const trigger_repo_id = (payload.workflow_run || current_run).head_repository.id; await Promise.all(workflow_ids.map(async (workflow_id) => { try { const { data: { total_count, workflow_runs }, } = await octokit.actions.listWorkflowRuns({ @@ -6139,7 +6140,8 @@ async function main() { .reduce((a, b) => Math.max(a, b), cancelBefore.getTime()); cancelBefore = new Date(n); } - const runningWorkflows = workflow_runs.filter(run => run.id !== current_run.id && + const runningWorkflows = workflow_runs.filter(run => run.head_repository.id === trigger_repo_id && + run.id !== current_run.id && (ignore_sha || run.head_sha !== headSha) && run.status !== 'completed' && new Date(run.created_at) < cancelBefore); diff --git a/src/index.ts b/src/index.ts index 81c47fdc..cfbb846e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,7 @@ async function main() { workflow_ids.push(String(current_run.workflow_id)); } console.log(`Found workflow_id: ${JSON.stringify(workflow_ids)}`); + const trigger_repo_id = (payload.workflow_run || current_run).head_repository.id; await Promise.all( workflow_ids.map(async workflow_id => { try { @@ -78,6 +79,7 @@ async function main() { } const runningWorkflows = workflow_runs.filter( run => + run.head_repository.id === trigger_repo_id && run.id !== current_run.id && (ignore_sha || run.head_sha !== headSha) && run.status !== 'completed' &&