Created
November 6, 2023 05:08
-
-
Save shakefu/bf492c2518a3e803501129dfbc556b36 to your computer and use it in GitHub Desktop.
GitHub Actions: Cancel a running workflow from within the workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Cancel workflow | |
uses: actions/github-script@v6 | |
if: steps.check.outputs.cancel == 'true' | |
with: | |
result-encoding: string | |
retries: 3 | |
script: | | |
github.rest.actions.cancelWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId, | |
}); | |
let count = 180; | |
const check = () => { | |
count -= 1; | |
github.rest.actions.getWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId, | |
}).then((run) => { | |
if (run.conclusion || run.status == "completed") { | |
return | |
} | |
console.log("Waiting for workflow to cancel") | |
console.log(run) | |
if (count > 0) { | |
setTimeout(check, 1000) | |
} else { | |
console.log("Workflow did not cancel in time") | |
} | |
}) | |
} | |
setTimeout(check, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment