diff --git a/dist/index.js b/dist/index.js index a675ed37..9d194284 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5894,9 +5894,9 @@ async function main() { const branchWorkflows = data.workflow_runs.filter(run => run.head_branch === branch); console.log(`Found ${branchWorkflows.length} runs for workflow ${workflow_id} on branch ${branch}`); console.log(branchWorkflows.map(run => `- ${run.html_url}`).join('\n')); - const runningWorkflows = branchWorkflows.filter(run => (ignore_sha || run.head_sha !== headSha) && - run.status !== 'completed' && - new Date(run.created_at) < new Date(current_run.created_at)); + let runningWorkflows = branchWorkflows.filter(run => run.status !== 'completed'); + runningWorkflows = runningWorkflows.filter(run => ignore_sha || run.head_sha !== headSha); + runningWorkflows = runningWorkflows.filter(run => new Date(run.created_at) < new Date(current_run.created_at)); console.log(`with ${runningWorkflows.length} runs to cancel.`); await cancelWorkflowRuns(runningWorkflows, owner, repo, token); } diff --git a/src/index.ts b/src/index.ts index d80c5f4e..9d611ad5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,12 +73,17 @@ async function main(): Promise { ); console.log(branchWorkflows.map(run => `- ${run.html_url}`).join('\n')); - const runningWorkflows = branchWorkflows.filter( - run => - (ignore_sha || run.head_sha !== headSha) && - run.status !== 'completed' && - new Date(run.created_at) < new Date(current_run.created_at) + // Filter for only uncompleted workflow runs + let runningWorkflows = branchWorkflows.filter(run => run.status !== 'completed'); + + // Filter out for only our headSha unless ignoring it + runningWorkflows = runningWorkflows.filter(run => ignore_sha || run.head_sha !== headSha); + + // Filter all workflow runs newer than ours + runningWorkflows = runningWorkflows.filter( + run => new Date(run.created_at) < new Date(current_run.created_at) ); + console.log(`with ${runningWorkflows.length} runs to cancel.`); await cancelWorkflowRuns(runningWorkflows, owner, repo, token); } catch (e) {