Skip to content

eBPF-based security platform

ci: build every commit of a pull request on its own

Daniel Borkmanncdbc39091819
diff --git a/.github/scripts/build-commits.sh b/.github/scripts/build-commits.sh
new file mode 100755
index 00000000..5e9875ba
--- /dev/null
+++ b/.github/scripts/build-commits.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# .github/scripts/build-commits.sh -- build every commit in a range on its
+# own, oldest first, so that the history bisects as
+# Documentation/contributing.rst asks: the binary, the shirudo-build helper
+# and the test helpers. The first commit that does not build is named and
+# the ones after it are not tried.
+#
+# .github/scripts/build-commits.sh [<rev-list arguments>]
+#
+# The arguments go to git rev-list: a range such as origin/main..HEAD, or
+# -3 HEAD. Without any, the commit at HEAD alone is built. The build runs
+# in the checkout itself, so uncommitted changes are refused first, and
+# the checkout is put back afterwards.
+
+set -eu
+
+cd "$(git rev-parse --show-toplevel)"
+
+if [ $# -eq 0 ]; then
+ set -- -1 HEAD
+fi
+
+if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
+ printf 'build-commits: the tree has uncommitted changes; commit or stash them first\n' >&2
+ exit 2
+fi
+
+head=$(git symbolic-ref -q --short HEAD || git rev-parse HEAD)
+trap 'git checkout -q "$head"' EXIT
+
+describe() {
+ git log -1 --format='%h ("%s")' "$1"
+}
+
+commits=$(git rev-list --reverse --no-merges "$@")
+n=$(printf '%s\n' "$commits" | grep -c . || :)
+i=0
+for c in $commits; do
+ i=$((i + 1))
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then
+ printf '::group::[%d/%d] %s\n' "$i" "$n" "$(describe "$c")"
+ else
+ printf '==== [%d/%d] %s\n' "$i" "$n" "$(describe "$c")"
+ fi
+ git checkout -q "$c"
+ if ! { make -j"$(nproc)" && make shirudo-build &&
+ make -C testing test-helpers; }; then
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then
+ printf '::endgroup::\n'
+ printf '::error::%s does not build on its own\n' "$(describe "$c")"
+ fi
+ printf 'build-commits: %s does not build on its own\n' "$(describe "$c")" >&2
+ exit 1
+ fi
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then
+ printf '::endgroup::\n'
+ fi
+done
+
+printf 'build-commits: %d commits built\n' "$n"
diff --git a/.github/scripts/vm-toolchain.sh b/.github/scripts/vm-toolchain.sh
new file mode 100755
index 00000000..b9975ab6
--- /dev/null
+++ b/.github/scripts/vm-toolchain.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# .github/scripts/vm-toolchain.sh -- prepare the LVH guest a workflow builds
+# in: check that its kernel takes signed BPF, install the build
+# dependencies and build an OpenSSL 3.5 toolchain, since the
+# distribution's predates ML-DSA. The environment the build then needs
+# is written to build/vm-toolchain.env for the caller to source.
+#
+# .github/scripts/vm-toolchain.sh [<apt package>...]
+#
+# Packages beyond the build dependencies, a sanitizer runtime for
+# instance, go on the command line. Runs as root in the guest, from any
+# directory; git is not available until it has been installed, so the
+# checkout is found from the script's own path.
+
+set -eu
+
+OPENSSL_VERSION=3.5.9
+OPENSSL_SHA256=603f5602e2eef00d77fbd429d34dcd5822bb301757a1bc9cdb24c670f1eb859a
+OPENSSL_PREFIX=/tmp/shirudo-openssl
+
+root=$(cd "$(dirname "$0")/../.." && pwd)
+
+grep -aq 'signature_size' /sys/kernel/btf/vmlinux || {
+ echo 'kernel BTF lacks bpf_attr.signature_size; needs a signed-BPF capable bpf-next kernel' >&2
+ exit 1
+}
+
+apt-get update
+apt-get install -y --no-install-recommends \
+ build-essential \
+ ca-certificates \
+ clang \
+ llvm \
+ curl \
+ git \
+ pkg-config \
+ python3 \
+ libcurl4-openssl-dev \
+ libelf-dev \
+ libluajit-5.1-dev \
+ libtpms-dev \
+ libtss2-dev \
+ zlib1g-dev \
+ "$@"
+
+# The checkout is mounted from the host under another owner.
+git config --global --add safe.directory "$root"
+
+tarball=openssl-$OPENSSL_VERSION.tar.gz
+curl -fsSL --retry 3 -o "/tmp/$tarball" \
+ "https://github.com/openssl/openssl/releases/download/openssl-$OPENSSL_VERSION/$tarball"
+printf '%s /tmp/%s\n' "$OPENSSL_SHA256" "$tarball" | sha256sum -c --quiet
+tar -C /tmp -xf "/tmp/$tarball"
+cd "/tmp/openssl-$OPENSSL_VERSION"
+./Configure --prefix="$OPENSSL_PREFIX" --openssldir=/etc/ssl --libdir=lib \
+ no-docs no-tests
+make -j"$(nproc)"
+make install_sw
+cd "$root"
+
+mkdir -p build
+cat >build/vm-toolchain.env <<EOT
+export PATH=$OPENSSL_PREFIX/bin:\$PATH
+export PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig
+export LD_LIBRARY_PATH=$OPENSSL_PREFIX/lib
+EOT
diff --git a/.github/workflows/build-commits.yml b/.github/workflows/build-commits.yml
new file mode 100644
index 00000000..75ffa269
--- /dev/null
+++ b/.github/workflows/build-commits.yml
@@ -0,0 +1,49 @@
+name: Build every commit
+
+on:
+ pull_request:
+
+permissions:
+ contents: read
+
+# A new push to the pull request supersedes the run in progress.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+jobs:
+ build-commits:
+ name: Build each commit on its own
+ runs-on: ubuntu-latest
+ timeout-minutes: 180
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ # Documentation/contributing.rst asks for every commit to build on
+ # its own, so that the history bisects; the other workflows build
+ # the head of the pull request alone. The BPF objects need the BTF
+ # of a signed-BPF capable bpf-next kernel, so the builds run in the
+ # same LVH VM as the package build. The guest does not inherit the
+ # runner's environment; GITHUB_ACTIONS is set for the annotations.
+ - name: Build every commit the pull request adds in LVH VM
+ uses: cilium/[email protected]
+ with:
+ test-name: shirudo-build-commits
+ image: kind
+ image-version: bpf-next-20260603.072225
+ kernel-version: bpf-next-main
+ host-mount: ${{ github.workspace }}
+ images-folder-parent: ${{ github.workspace }}/../lvh
+ install-dependencies: true
+ cpu: 4
+ mem: 8G
+ cmd: |
+ cd /host
+ .github/scripts/vm-toolchain.sh
+ . build/vm-toolchain.env
+ GITHUB_ACTIONS=true .github/scripts/build-commits.sh \
+ ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
diff --git a/AGENTS.md b/AGENTS.md
index 7373bdb5..3ac1c9e7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -307,7 +307,9 @@ one usually still compiles and passes tests.
checkpatch.pl in strict mode over the C each commit touches and over
its message, with the userspace exceptions listed in the script, and
rejects the netdev block-comment opener. CI runs all three on every
- pull request; run them before handing work over.
+ pull request, and `.github/scripts/build-commits.sh <range>` builds
+ every commit of a pull request on its own; run them before handing
+ work over.
- Shell that a workflow runs lives in `.github/scripts/`, not inline in
the workflow file.
- `make -C packaging bindeb-pkg`, `make -C packaging binrpm-pkg` and `make -C packaging bintar-pkg` build the
diff --git a/Documentation/contributing.rst b/Documentation/contributing.rst
index a58f009a..5b51607b 100644
--- a/Documentation/contributing.rst
+++ b/Documentation/contributing.rst
@@ -223,7 +223,10 @@ Before sending
whole files and ``--types`` lists what stays enabled. CI runs it as
the ``Checkpatch`` check.
* Keep each commit to one logical change that builds and passes on its
- own, so the history bisects.
+ own, so the history bisects. CI builds every commit of a pull request
+ on its own as the ``Build every commit`` check;
+ ``.github/scripts/build-commits.sh origin/main..HEAD`` does the same
+ locally.
* Read `threat-model <threat-model.rst>`__ before changing anything on a
security-relevant path, and say in the commit message which invariant
the change preserves or extends.