Is there an option to cancel runs for all scheduled github actions in one repository at once. To always go here and cancel runs is a lot of clicking. Thanks
Is there an option to cancel runs for all scheduled github actions in one repository at once. To always go here and cancel runs is a lot of clicking. Thanks
You can use Github Actions API to list workflow runs and cancel workflows runs.
The following script use curl bash and jq to :
queued or in_progressTo run the script below you will need a personnal access token with repo scope :
token=YOUR_TOKEN
repo=your_user/your_repo
ids=$(curl -s -H "Authorization: token $token" \
https://api.github.com/repos/$repo/actions/runs | \
jq '.workflow_runs[] | select([.status] | inside(["in_progress", "queued"])) | .id')
set -- $ids
for i; do curl \
-H "Authorization: token $token" \
-X POST "https://api.github.com/repos/$repo/actions/runs/$i/cancel"; done
You also have, in Oct. 2021, gh run cancel
This comes from the GitHub CLI gh 2.2.0 and feature request 3775 (Support canceling workflow runs), implemented in PR 3833 and commit 06c06c8
gh run cancel [<run-id>] [flags]
gh run list can list your workflow runs ID first.
I created this small script to manually cancel all unfinished jobs for a given branch or pull request:
Example:
# Set up
export GITHUB_TOKEN=394ba3b48494ab8f930fbc93
export GITHUB_REPOSITORY=apache/incubator-superset
# Cancel previous jobs for a PR
./cancel_github_workflows.py 1042
# Cancel previous jobs for a branch
./cancel_github_workflows.py my-branch
# Cancel all jobs including the last ones, this is useful
# when you have closed a PR or deleted a branch and want
# to cancel all its jobs.
./cancel_github_workflows.py 1024 --include-last
gh run list + powershell:
gh run list --limit 5000 --json status,databaseId -q ".[] | select (.status == \`"queued\`" ) | .databaseId" | ForEach-Object -Process { gh run cancel $_ }
Gets first 5000 workflows, filters it by "status" == "queued" and passes it to "gh run cancel"
Here is my GNU one-liner for cancelling all current runs:
$ gh run list --json databaseId -q '.[].databaseId' \
| xargs -d '\n' -n1 gh run cancel