eBPF-based security platform
ci: pick the commits an event covers in one script
Daniel Borkmann00e60edee52a
diff --git a/.github/scripts/ci-commit-range.sh b/.github/scripts/ci-commit-range.shnew file mode 100755index 00000000..690d9b4d--- /dev/null+++ b/.github/scripts/ci-commit-range.sh@@ -0,0 +1,36 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/ci-commit-range.sh -- run a checker over the commits a+# GitHub event covers: every commit a pull request adds, or a push brings+# to the branch. A push whose previous tip is unknown, after a force push,+# is checked at the pushed tip alone.+#+# .github/scripts/ci-commit-range.sh <command> [<argument>...]+#+# The command runs with the rev-list arguments for the range appended,+# the form check-dco.sh and check-style.sh take. The event comes from the+# environment the workflow sets: EVENT_NAME, and BASE_SHA and HEAD_SHA for+# a pull request, BEFORE_SHA and SHA for a push.++set -eu++[ $# -gt 0 ] || {+ printf 'usage: %s <command> [<argument>...]\n' "$0" >&2+ exit 2+}++if [ "${EVENT_NAME:-}" = pull_request ]; then+ set -- "$@" "${BASE_SHA:?}..${HEAD_SHA:?}"+elif git cat-file -e "${BEFORE_SHA:-}^{commit}" 2>/dev/null; then+ set -- "$@" "$BEFORE_SHA..${SHA:?}"+else+ if [ -n "${GITHUB_ACTIONS:-}" ]; then+ printf '::notice::previous tip %s is unknown; checking the pushed tip alone\n' \+ "${BEFORE_SHA:-}"+ fi+ set -- "$@" -1 "${SHA:?}"+fi++exec "$@"diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.ymlindex b6177ec7..ff437176 100644--- a/.github/workflows/dco.yml+++ b/.github/workflows/dco.yml@@ -21,9 +21,8 @@ jobs:fetch-depth: 0# Every commit a pull request adds, or a push brings to main, needs- # a subject, a body and its author's sign-off. A push whose previous- # tip is unknown, after a force push, is checked at the pushed tip- # alone.+ # a subject, a body and its author's sign-off; ci-commit-range.sh+ # picks the commits the event covers.- name: Check the sign-off of every commitenv:EVENT_NAME: ${{ github.event_name }}@@ -31,13 +30,4 @@ jobs:HEAD_SHA: ${{ github.event.pull_request.head.sha }}BEFORE_SHA: ${{ github.event.before }}SHA: ${{ github.sha }}- run: |- if [ "$EVENT_NAME" = pull_request ]; then- set -- "$BASE_SHA..$HEAD_SHA"- elif git cat-file -e "$BEFORE_SHA^{commit}" 2>/dev/null; then- set -- "$BEFORE_SHA..$SHA"- else- echo "::notice::previous tip $BEFORE_SHA is unknown; checking the pushed tip alone"- set -- -1 "$SHA"- fi- .github/scripts/check-dco.sh "$@"+ run: .github/scripts/ci-commit-range.sh .github/scripts/check-dco.shdiff --git a/AGENTS.md b/AGENTS.mdindex d68faa18..7c9fc8c5 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -303,6 +303,8 @@ one usually still compiles and passes tests.that every commit has a one-line subject, a body beyond its tags andthe author's sign-off. CI runs both on every pull request; run thembefore 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 thedistribution packages. The target package is static apart from glibcand portable; the operator package links the host's shared librariesdiff --git a/testing/t0044-ci-commit-range.sh b/testing/t0044-ci-commit-range.shnew file mode 100644index 00000000..a5aae485--- /dev/null+++ b/testing/t0044-ci-commit-range.sh@@ -0,0 +1,57 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t0044 -- .github/scripts/ci-commit-range.sh: the rev-list arguments a+# pull request, a push and a force push hand to a checker, on a throwaway+# repository.++cd "$(dirname "$0")"+. ./test-lib.sh+command -v git >/dev/null 2>&1 || test_skip_all "git not installed"+S=$(cd .. && pwd)/.github/scripts/ci-commit-range.sh+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT+R=$W/repo+export GIT_AUTHOR_NAME='Random J Developer' GIT_AUTHOR_EMAIL='[email protected]'+export GIT_COMMITTER_NAME='Random J Developer' GIT_COMMITTER_EMAIL='[email protected]'+git init -q "$R"+git -C "$R" config commit.gpgsign false+git -C "$R" commit -q --allow-empty -m first+first=$(git -C "$R" rev-parse HEAD)+git -C "$R" commit -q --allow-empty -m second+second=$(git -C "$R" rev-parse HEAD)++# The checker under the script is printf, so its arguments come back one+# per line, the checker's own first.+run() {+ (cd "$R" && env "$@" sh "$S" printf '%s\n' own) >"$W/out" 2>"$W/err"+}++test_expect_success 'a pull request covers base..head after the command arguments' '+ run EVENT_NAME=pull_request BASE_SHA=$first HEAD_SHA=$second &&+ [ "$(sed -n 1p "$W/out")" = own ] &&+ [ "$(sed -n 2p "$W/out")" = "$first..$second" ]+'++test_expect_success 'a push covers the previous tip to the new one' '+ run EVENT_NAME=push BEFORE_SHA=$first SHA=$second &&+ [ "$(sed -n 2p "$W/out")" = "$first..$second" ]+'++test_expect_success 'a push from an unknown tip covers the new tip alone' '+ run EVENT_NAME=push BEFORE_SHA=0000000000000000000000000000000000000000 SHA=$second &&+ [ "$(sed -n 2p "$W/out")" = -1 ] &&+ [ "$(sed -n 3p "$W/out")" = "$second" ]+'++test_expect_success 'a pull request without its shas fails' '+ ! run EVENT_NAME=pull_request+'++test_expect_success 'no command is a usage error' '+ ! (cd "$R" && EVENT_NAME=push SHA=$second sh "$S") 2>"$W/err" &&+ grep -q "^usage:" "$W/err"+'++test_done