Skip to content

eBPF-based security platform

ci: stop a merge to main from cancelling the run of the one before

Tobias Klauser779bb01b9f5a
diff --git a/.github/scripts/is-main-head.sh b/.github/scripts/is-main-head.sh
new file mode 100755
index 00000000..68304669
--- /dev/null
+++ b/.github/scripts/is-main-head.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# .github/scripts/is-main-head.sh -- tell whether the commit a run was
+# started for is still the head of main: writes current=true or
+# current=false to $GITHUB_OUTPUT.
+#
+# .github/scripts/is-main-head.sh
+#
+# The commit is SHA, the repository GITHUB_REPOSITORY, and gh reads the
+# token from GH_TOKEN.
+
+set -eu
+
+head=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq .object.sha)
+if [ "$head" = "$SHA" ]; then
+ echo "current=true" >>"$GITHUB_OUTPUT"
+else
+ echo "::notice::main moved on from $SHA to $head, whose run takes over"
+ echo "current=false" >>"$GITHUB_OUTPUT"
+fi
diff --git a/.github/workflows/build-commits.yml b/.github/workflows/build-commits.yml
index 4ba051f4..6a386049 100644
--- a/.github/workflows/build-commits.yml
+++ b/.github/workflows/build-commits.yml
@@ -9,9 +9,13 @@ on:
permissions:
contents: read
-# A new push to the pull request supersedes the run in progress.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 072362a2..2feec04e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -9,9 +9,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index c361db84..54c84230 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -9,9 +9,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.yml
index 3ef05de2..65ae3f12 100644
--- a/.github/workflows/dco.yml
+++ b/.github/workflows/dco.yml
@@ -9,9 +9,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index a005973d..7ba8a123 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -15,11 +15,14 @@ permissions:
jobs:
docs:
runs-on: ubuntu-latest
- # A newer run for the same pull request supersedes this one. On main a
- # render in flight finishes, so a busy main still deploys.
+ # A newer push to a pull request supersedes its run. Any other run is
+ # keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
- cancel-in-progress: ${{ github.event_name == 'pull_request' }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
+ cancel-in-progress: true
steps:
- name: Check out repository
@@ -66,6 +69,21 @@ jobs:
cancel-in-progress: false
steps:
+ - name: Check out the CI scripts
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ sparse-checkout: .github/scripts
+
+ # Renders on main can finish out of order: only main's head deploys.
+ - name: Check that main has not moved on
+ id: head
+ env:
+ GH_TOKEN: ${{ github.token }}
+ SHA: ${{ github.sha }}
+ run: .github/scripts/is-main-head.sh
+
- name: Deploy to GitHub Pages
+ if: steps.head.outputs.current == 'true'
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 834c5cb7..a211fb60 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -9,9 +9,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml
index 73d29658..0e4c83d1 100644
--- a/.github/workflows/packages.yml
+++ b/.github/workflows/packages.yml
@@ -18,9 +18,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
@@ -343,6 +347,11 @@ jobs:
needs: [deb, rpm-target]
runs-on: ubuntu-latest
timeout-minutes: 30
+ # bpm push rewrites the signed index, so publishes run one at a time.
+ # GitHub drops all but the newest waiting one, the greatest version.
+ concurrency:
+ group: ${{ github.workflow }}-kernel-obs-publish
+ cancel-in-progress: false
environment:
name: kernel-obs
permissions:
diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml
index 62f9dade..f4aadead 100644
--- a/.github/workflows/sanitizers.yml
+++ b/.github/workflows/sanitizers.yml
@@ -12,9 +12,13 @@ on:
permissions:
contents: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index c0e40a54..5e383ec3 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -16,9 +16,13 @@ permissions:
contents: read
actions: read
-# A newer run for the same branch or pull request supersedes this one.
+# A newer push to a pull request supersedes its run. Any other run is
+# keyed on its ref and commit, so a merge never cancels another's run.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ group: |
+ ${{ github.workflow }}
+ ${{ github.event_name }}
+ ${{ github.event.pull_request.number || format('{0}@{1}', github.ref, github.sha) }}
cancel-in-progress: true
jobs: