You will also want to make sure you account for having multiple workflows in the same repository so that you only cancel in-progress runs of the same workflow.
Snippet from the Using concurrency GitHub docs:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Full, working example (Source):
name: CI with in-progress cancellations
on:
pull_request:
branches: [ main ]
workflow_dispatch:
# This is what will cancel the workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Print concurrency group
run: echo '${{ github.workflow }}-${{ github.ref }}'
- name: Sleep 15s
run: sleep 15s