Search code examples
gitgithubyamlgithub-actions

How to cancel previous runs in the PR when you push new commits(update the current) in github-actions


When I push my commits to a PR my tests are triggered for this commit. After that, if I push additional commits to this PR, tests in Github Actions runs on both commits.

I need to cancel the previous run and run only on the most recent pushed commit.

How can I configure my yaml file to achieve that?


Solution

  • You can use Concurrency:

    Concurrency ensures that only a single job or workflow using the same concurrency group will run at a time.

    concurrency: 
      group: ${{ github.head_ref }}
      cancel-in-progress: true