Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
stop-circle

GitHub Action

Cancel Workflow Action

0.3.2

Cancel Workflow Action

stop-circle

Cancel Workflow Action

This Action will cancel any previous runs that are not `completed` for a given workflow

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Cancel Workflow Action

uses: styfle/cancel-workflow-action@0.3.2

Learn more about this action in styfle/cancel-workflow-action

Choose a version

Cancel Workflow Action

This is a Github Action that will cancel any previous runs that are not completed for a given workflow.

This includes runs with a status of queued or in_progress.

How does it work?

When you git push, this action will capture the Branch and SHA. It will query GitHub's API to find workflow runs that match the Branch but do not match the SHA (these would be previous pushes) and cancel all of these in-progress runs so that the latest run (current SHA) will finish.

Read more about the Workflow Runs API.

Usage

  • Visit https://api.github.com/repos/:org/:repo/actions/workflows to find the Workflow ID you wish to auto-cancel.
  • Add a new file .github/workflows/cancel.yml with the following:
name: Cancel
on: [push]
jobs:
  cancel:
    name: 'Cancel Previous Runs'
    runs-on: ubuntu-latest
    timeout-minutes: 3
    steps:
      - uses: styfle/cancel-workflow-action@0.3.1
        with:
          workflow_id: 479426
          access_token: ${{ github.token }}

Note: workflow_id accepts a comma separated list of IDs.

At the time of writing 0.3.1 is the latest release but you can select any release.

Contributing

  • Clone this repo
  • Run yarn install
  • Edit ./src/index.ts
  • Run yarn build
  • Commit changes including ./dist/index.js bundle