{"id":13626477,"url":"https://github.com/styfle/cancel-workflow-action","last_synced_at":"2025-05-14T09:09:38.538Z","repository":{"id":37509957,"uuid":"237695528","full_name":"styfle/cancel-workflow-action","owner":"styfle","description":"⏹️ GitHub Action to cancel previous running workflows on push","archived":false,"fork":false,"pushed_at":"2024-04-29T03:01:14.000Z","size":434,"stargazers_count":953,"open_issues_count":4,"forks_count":120,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-03T16:07:49.920Z","etag":null,"topics":["actions","github-actions","workflows"],"latest_commit_sha":null,"homepage":"https://github.com/marketplace/actions/cancel-workflow-action","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/styfle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"styfle"}},"created_at":"2020-02-02T00:01:51.000Z","updated_at":"2025-03-27T19:14:16.000Z","dependencies_parsed_at":"2024-01-25T17:40:57.544Z","dependency_job_id":"5e85b62e-332d-4e3c-98f9-950f2dec1947","html_url":"https://github.com/styfle/cancel-workflow-action","commit_stats":{"total_commits":177,"total_committers":23,"mean_commits":7.695652173913044,"dds":0.5254237288135593,"last_synced_commit":"034d0e91921de4e82c4b8c958df266ca615543e8"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styfle%2Fcancel-workflow-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styfle%2Fcancel-workflow-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styfle%2Fcancel-workflow-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/styfle%2Fcancel-workflow-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/styfle","download_url":"https://codeload.github.com/styfle/cancel-workflow-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248334968,"owners_count":21086485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","github-actions","workflows"],"created_at":"2024-08-01T21:02:20.077Z","updated_at":"2025-04-11T03:27:14.024Z","avatar_url":"https://github.com/styfle.png","language":"TypeScript","funding_links":["https://github.com/sponsors/styfle"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003e [!IMPORTANT]\n\u003e You probably don't need to install this custom action.\n\u003e \n\u003e Instead, use the native [concurrency](https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/) property to cancel workflows, for example:\n\u003e ```\n\u003e concurrency:\n\u003e   group: ${{ github.workflow }}-${{ github.ref }}\n\u003e   cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}\n\u003e ```\n\u003e Read GitHub's [official documentation](https://docs.github.com/en/actions/using-jobs/using-concurrency) to learn more.\n\n# Cancel Workflow Action\n\nThis is a GitHub Action that will cancel any previous runs that are not `completed` for a given workflow.\n\nThis includes runs with a [status](https://docs.github.com/en/rest/reference/checks#check-runs) of `queued` or `in_progress`.\n\n## How does it work?\n\nWhen you `git push`, this GitHub Action will capture the current Branch and SHA. It will query GitHub's API to find previous workflow runs that match the Branch but do not match the SHA. These in-progress runs will be canceled leaving only this run, or the [latest run](#advanced-all-but-latest).\n\nRead more about the [Workflow Runs API](https://docs.github.com/en/rest/reference/actions#workflow-runs).\n\n## Usage\n\nTypically, you will want to add this action as the first step in a workflow so it can cancel itself on the next push.\n\n```yml\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Cancel Previous Runs\n        uses: styfle/cancel-workflow-action\n      #- name: Run Tests\n      #  uses: actions/setup-node\n      #  run: node test.js\n      # ... etc\n```\n\n### Versioning\n\nIt is recommended to pin a specific version of this action so you don't automatically upgrade to the latest which could introduce breaking changes.\n\n```yml\nuses: styfle/cancel-workflow-action@0.9.1\n```\n\nNotice there is no `v` prefix, just the `@major.minor.patch` version.\n\nVisit [Releases](https://github.com/styfle/cancel-workflow-action/releases) to find the latest version at the top of the page.\n\n\u003e **Warning**\n\u003e \n\u003e You might run into \"the `uses' attribute must be a path, a Docker image, or owner/repo@ref\" error if you don't specify a version.\n\n### Advanced: Canceling Other Workflows\n\nIn some cases, you may wish to avoid modifying all your workflows and instead create a new workflow that cancels your other workflows. This can be useful when you have a problem with workflows getting queued.\n\n- Visit `https://api.github.com/repos/:org/:repo/actions/workflows` to find the Workflow ID(s) you wish to automaticaly cancel.\n- Add a new file `.github/workflows/cancel.yml` with the following:\n\n```yml\nname: Cancel\non: [push]\njobs:\n  cancel:\n    name: 'Cancel Previous Runs'\n    runs-on: ubuntu-latest\n    timeout-minutes: 3\n    steps:\n      - uses: styfle/cancel-workflow-action\n        with:\n          workflow_id: 479426\n```\n\n- _Note_: `workflow_id` can be a Workflow ID (number) or Workflow File Name (string)\n- _Note_: `workflow_id` also accepts a comma separated list if you need to cancel multiple workflows\n- _Note_: `workflow_id` accepts the value `all`, which will cancel all the workflows running in the branch\n\n\n### Advanced: Pull Requests from Forks\n\nThe default GitHub token access is unable to cancel workflows for `pull_request`\nwhen a pull request is opened from a fork. Therefore, a special setup using\n`workflow_run`, which also works for `push`, is needed.\nCreate a `.github/workflows/cancel.yml` with the following instead and replace\n\"CI\" with the workflow name that contains the `pull_request` workflow:\n\n```yml\nname: Cancel\non:\n  workflow_run:\n    workflows: [\"CI\"]\n    types:\n      - requested\njobs:\n  cancel:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: styfle/cancel-workflow-action\n      with:\n        workflow_id: ${{ github.event.workflow.id }}\n```\n\n### Advanced: Ignore SHA\n\nIn some cases, you may wish to cancel workflows when you close a Pull Request. Because this is not a push event, the SHA will be the same, so you must use the `ignore_sha` option.\n\n```yml\non:\n  pull_request:\n    types: [closed]\njobs:\n  cleanup:\n    name: 'Cleanup After PR Closed'\n    runs-on: ubuntu-latest\n    timeout-minutes: 3\n    steps:\n      - name: Cancel build runs\n        uses: styfle/cancel-workflow-action\n        with:\n          ignore_sha: true\n          workflow_id: 479426\n```\n\n### Advanced: All But Latest\n\nBecause this action can only cancel workflows if it is actually being run, it only helps if the pipeline isn't saturated and there are still runners available to schedule the workflow.\n\nBy default, this action does not cancel any workflows created after itself. The `all_but_latest` flags allows the action to cancel itself and all later-scheduled workflows, leaving only the latest.\n\n```yml\nname: Cancel\non: [push]\njobs:\n  cancel:\n    name: 'Cancel Previous Runs'\n    runs-on: ubuntu-latest\n    timeout-minutes: 3\n    steps:\n      - uses: styfle/cancel-workflow-action\n        with:\n          all_but_latest: true\n```\n\n### Advanced: Skip runs that are in progress\n\nSome workflows may be dangerous to cancel when they are in progress. If you want to play safe and cancel only workflows that are in state `waiting`, most likely waiting for approval to be deployed in a protected environment, use `only_status` to only cancel runs with a specific status. \n\n```yml\nname: Cancel\non: [push]\njobs:\n  cancel:\n    name: 'Cancel Previous Runs'\n    runs-on: ubuntu-latest\n    timeout-minutes: 3\n    steps:\n      - uses: styfle/cancel-workflow-action\n        with:\n          only_status: 'waiting'\n```\n\n### Advanced: Token Permissions\n\nNo change to permissions is required by default. The instructions below are for improved control over of those permissions.\n\nBy default, GitHub creates the `GITHUB_TOKEN` for Actions with some read/write permissions. It may be a good practice to switch to read-only permissions by default. Visit the [dedicated documentation page](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/disabling-or-limiting-github-actions-for-a-repository#setting-the-permissions-of-the-github_token-for-your-repository) for details.\n\nPermissions can be set for all Jobs in a Workflow or a specific Job, see the [reference manual page](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions). `cancel-workflow-action` only requires write access to the `actions` scope, so it is enough to have:\n\n```yml\njobs:\n  test:\n    runs-on: ubuntu-latest\n    permissions:\n      actions: write\n    steps:\n      - name: Cancel Previous Runs\n        uses: styfle/cancel-workflow-action\n        with:\n          access_token: ${{ github.token }}\n```\n\n_Note_ : This is typical when global access is set to be restrictive. Only this job will elevate those permissions.\n\n## Contributing\n\n- Clone this repo\n- Run `yarn install`\n- Edit `./src/index.ts`\n- Run `yarn build`\n- Run `yarn format`\n- Commit changes including `./dist/index.js` bundle\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyfle%2Fcancel-workflow-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstyfle%2Fcancel-workflow-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstyfle%2Fcancel-workflow-action/lists"}