workflows: cancel running jobs on pull request updates

We can avoid running old jobs to completion, when pushing changes to a
pull request. This is done via concurrency groups. We set them on the
workflow level, with the following keys in the group name:
- `github.workflow` to only cancel / block the same workflow.
- `github.event_name` to avoid blocking between pull_request and
pull_request_target.
- `github.head_ref` which is unique for a PR, but the same when changing
it. This will cause PRs to cancel in progress jobs. Unset on pushes to
master & co.
- `github.run_id` as fallback for push events. In this case, the run_id
is unique for every push, thus *no* cancelling happens on the dev
branches.
This commit is contained in:
Wolfgang Walther 2025-05-27 16:48:28 +02:00
parent 93469ba1c5
commit 6d4b1f8e30
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1
14 changed files with 63 additions and 0 deletions

View file

@ -10,6 +10,10 @@ on:
- 'staging-**'
- '!staging-next'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
pull-requests: write

View file

@ -6,6 +6,10 @@ on:
- .github/workflows/check-format.yml
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -9,6 +9,10 @@ on:
- 'shell.nix'
- 'ci/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -29,6 +29,10 @@ on:
pull_request_target:
types: [opened, ready_for_review, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
env:

View file

@ -16,6 +16,10 @@ on:
pull_request_target:
types: [edited]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -6,6 +6,10 @@ on:
- .github/workflows/eval-aliases.yml
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -16,6 +16,10 @@ on:
- haskell-updates
- python-updates
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:
@ -290,3 +294,5 @@ jobs:
if: needs.prepare.outputs.targetSha
uses: ./.github/workflows/reviewers.yml
secrets: inherit
with:
caller: ${{ github.workflow }}

View file

@ -8,6 +8,10 @@ name: "Label PR"
on:
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
issues: write # needed to create *new* labels

View file

@ -9,6 +9,10 @@ on:
- 'lib/**'
- 'maintainers/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -18,6 +18,10 @@ on:
# Since the lib functions are used to 'massage' the options before producing the manual
- "lib/**"
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -10,6 +10,10 @@ on:
- 'lib/**'
- 'pkgs/by-name/ni/nixdoc/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -6,6 +6,10 @@ on:
- .github/workflows/nix-parse-v2.yml
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:

View file

@ -11,6 +11,10 @@ on:
- .github/workflows/nixpkgs-vet.yml
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
# We don't use a concurrency group here, because the action is triggered quite often (due to the PR edit trigger), and contributors would get notified on any canceled run.

View file

@ -10,6 +10,15 @@ on:
pull_request_target:
types: [ready_for_review]
workflow_call:
inputs:
caller:
description: Name of the calling workflow.
required: true
type: string
concurrency:
group: ${{ inputs.caller }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}