Interview Prep/GitHub Actions/Jobs, Steps, Matrix & Concurrency

How do you cancel in progress only for PRs but not on `main`?

IntermediateConceptJobs, Steps, Matrix & Concurrency
Answer

cancel-in-progress accepts an expression:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

On main every commit's pipeline finishes (useful when each merge must produce an image), while PR branches drop stale runs.

All GitHub Actions questions Roadmap: GitHub Actions

More on Jobs, Steps, Matrix & Concurrency