Skip to content

eBPF-based security platform

ci: build every commit a push adds to main as well

Daniel Borkmann5662cbb73f7b
diff --git a/.github/scripts/build-commits.sh b/.github/scripts/build-commits.sh
index de42798c..7d3d879a 100755
--- a/.github/scripts/build-commits.sh
+++ b/.github/scripts/build-commits.sh
@@ -12,9 +12,10 @@
# .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.
+# -3 HEAD. Without any, the commit at HEAD alone is built. A range whose
+# start the clone lacks, as after a force push, builds its end alone. The
+# build runs in the checkout itself, so uncommitted changes are refused
+# first, and the checkout is put back afterwards.
set -eu
@@ -23,6 +24,15 @@ cd "$(git rev-parse --show-toplevel)"
if [ $# -eq 0 ]; then
set -- -1 HEAD
fi
+case $1 in
+*..*)
+ if [ $# -eq 1 ] && ! git cat-file -e "${1%%..*}^{commit}" 2>/dev/null; then
+ printf 'build-commits: no %s here; building %s alone\n' \
+ "${1%%..*}" "${1#*..}" >&2
+ set -- -1 "${1#*..}"
+ fi
+ ;;
+esac
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
printf 'build-commits: the tree has uncommitted changes; commit or stash them first\n' >&2
diff --git a/.github/workflows/build-commits.yml b/.github/workflows/build-commits.yml
index c6a22894..575933f5 100644
--- a/.github/workflows/build-commits.yml
+++ b/.github/workflows/build-commits.yml
@@ -1,6 +1,9 @@
name: Build every commit
on:
+ push:
+ branches:
+ - main
pull_request:
permissions:
@@ -8,7 +11,7 @@ permissions:
# A new push to the pull request supersedes the run in progress.
concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
@@ -25,11 +28,11 @@ jobs:
# Documentation/contribute/code/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
+ # build the head of the pull request or of main 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
+ - name: Build every commit the pull request or push adds in LVH VM
uses: cilium/little-vm-helper@c8b0bfbae3bdda7bc69fb9cd370e4b74ce84986d # v0.0.33
with:
test-name: shirudo-build-commits
@@ -44,4 +47,4 @@ jobs:
.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 }}
+ ${{ github.event_name == 'pull_request' && format('{0}..{1}', github.event.pull_request.base.sha, github.event.pull_request.head.sha) || format('{0}..{1}', github.event.before, github.sha) }}
diff --git a/Documentation/contribute/code/contributing.rst b/Documentation/contribute/code/contributing.rst
index 358da1bd..a24edb59 100644
--- a/Documentation/contribute/code/contributing.rst
+++ b/Documentation/contribute/code/contributing.rst
@@ -269,8 +269,9 @@ Before sending
opened without close-on-exec or a pointer tested for NULL after its
use. CI runs it as the ``Coccinelle`` job of the ``Lint`` workflow.
- Keep each commit to one logical change that builds and passes on its
- own, so the history bisects. CI builds every commit of a pull request
- on its own in the ``Build every commit`` workflow.
+ own, so the history bisects. CI builds every commit of a pull request,
+ and every commit a push adds to ``main``, on its own in the
+ ``Build every commit`` workflow.
``.github/scripts/build-commits.sh origin/main..HEAD`` does the same
locally.
- Read :doc:`/security/threat-model` before changing anything on a