-
Notifications
You must be signed in to change notification settings - Fork 4
Include completed successful runs when deduplicating #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… existing runs if the provided sha is different
is everything ok with this? |
core.debug(inspect(prime)) | ||
|
||
for (const run of cancellable) { | ||
if (run.status === 'completed') continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this would work ...
but, wouldn't it better to first check if there is a completed run FIRST (before getting this deep) and if one is already completed, exit early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for the least amount of logic changes that would do the trick, my test version looked like this (sort and map no longer needed, just filter the runs and if the list is not empty just cancel the current workflow - it proved very reliable in my case, but I didn't want to force my luck :) ):
// filter
const current_runs = workflow_runs
// exclude this one
.filter(run => run.id !== run_id)
// filter to only runs for the same commit
.filter(run => run.head_sha === sha)
// filter out unsuccessful completed runs (cancelled / failed)
.filter(run => (run.status !== 'completed') || (run.conclusion === 'success'))
core.info(`found ${current_runs.length} existing runs of workflow ${workflow_id} for sha ${sha}`)
if(current_runs.length > 0) {
core.info('successful or in-progress runs found, bailing out')
await octokit.request('POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel', {
...github.context.repo,
run_id: run_id
})
}
sorry I missed the notification for this, reviewed now |
I'm also facing the same issue covered by this PR. |
@m0n5t3r or @GiuseppeChiesa-TomTom did you find a better solution? |
This fixes the issue from #3 (comment):

Basically, if you have 3 (or more) upstream workflows, each of them will trigger a run of the workflow calling this action (let's call it "Deploy", as in the image); the current code looks for other in progress or queued runs of the same workflow for the same hash as the current one, and cancels all but the first started one.
This creates a race condition, because:
This PR adds completed successful workflows of the same SHA as the current run to the list of cancellable runs, allowing the action to cancel the current workflow if it already ran successfully for the same commit before.