Skip to content

Instantly share code, notes, and snippets.

@ericphanson
Created October 17, 2021 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericphanson/7340da7345e80cb037ce4bad5f3f70e0 to your computer and use it in GitHub Desktop.
Save ericphanson/7340da7345e80cb037ce4bad5f3f70e0 to your computer and use it in GitHub Desktop.
GitHub actions workflow for cancelling CI when a newer commit is pushed
name: Cancel
on:
push:
branches:
- main
- master
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
cancel:
name: 'Cancel Previous Runs'
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions
# we only need actions write:
permissions:
actions: write
timeout-minutes: 3
steps:
- uses: styfle/cancel-workflow-action@0.9.1
with:
# Put in the filenames of whatever workflows you want to cancel when a newer commit is pushed:
workflow_id: CI.yml,docs.yml,doctests.yml,format-check.yml
access_token: ${{ github.token }}
# When this workflow runs on a branch, it will cancel all workflows (according to the names above)
# except for the latest ones.
all_but_latest: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment