-
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?
Changes from 3 commits
7390a5a
acd4af7
59c0ee6
84ae5e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,11 @@ export default async function ({ octokit, workflow_id, run_id }) { | |
| // filter and sort | ||
| const cancellable = workflow_runs | ||
| // filter to relevant runs | ||
| .filter(run => ['in_progress', 'queued'].includes(run.status)) | ||
| .filter(run => ['in_progress', 'queued', 'completed'].includes(run.status)) | ||
| // 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')) | ||
| // pick relevant properties | ||
| .map(run => ({ id: run.id, name: run.name, created_at: run.created_at })) | ||
| // sort | ||
|
|
@@ -46,6 +48,8 @@ export default async function ({ octokit, workflow_id, run_id }) { | |
| core.debug(inspect(prime)) | ||
|
|
||
| for (const run of cancellable) { | ||
| if (run.status === 'completed') continue | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
})
} |
||
|
|
||
| core.info(`${run.name}#${run.id} => canceling`) | ||
|
|
||
| await octokit.request('POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel', { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.