strawberry/packaging/ci/build-release.sh
trvon 933a05c3bf
Some checks failed
release / draft (push) Has been skipped
release / build (debian:forky, forky) (push) Failing after 4m13s
release / build (debian:trixie, trixie) (push) Successful in 1h6m14s
release / build (ubuntu:24.04, noble) (push) Successful in 1h1m20s
release / publish (push) Has been skipped
release: add a Debian forky (testing) build leg
The Security Hub server runs Debian forky; build-release.sh accepts forky and the
release matrix gains a debian:forky leg (~1 h more per release, legs run one at a
time). Testing moves: rebuild after a library transition.
2026-11-20 07:44:12 -07:00

89 lines
3.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build, test and pack a Linux install tree for one distro. CI containers only:
# it installs build packages with apt.
#
# packaging/ci/build-release.sh <trixie|noble|forky> [outdir]
#
# Output: <outdir>/strawberry-<version>-<os>-<arch>.tgz and a .sha256 next to it.
# The tarball holds what scripts/install.sh reads from a source tree:
# builddir/src/strawberry, builddir/src/process_monitor.bpf.o, scripts/, config/, packaging/.
# packaging/ includes rules-snapshot/ (pinned default YARA feed, installed by install.sh).
set -euo pipefail
os=${1:?usage: build-release.sh <trixie|noble|forky> [outdir]}
out=${2:-dist}
jobs=${JOBS:-2}
case "$os" in
trixie) want_id=debian want_codename=trixie ;;
noble) want_id=ubuntu want_codename=noble ;;
forky) want_id=debian want_codename=forky ;;
*) echo "unsupported os: $os" >&2; exit 2 ;;
esac
if [ "${CI:-}" != "true" ]; then
echo "refusing to run outside CI (it installs packages); set CI=true in a throwaway container" >&2
exit 2
fi
. /etc/os-release
if [ "$ID" != "$want_id" ] || [ "${VERSION_CODENAME:-}" != "$want_codename" ]; then
echo "container is $ID ${VERSION_CODENAME:-?}, expected $want_id $want_codename" >&2
exit 2
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update -q
# Same set as the Dockerfile base stage, minus Qt (the tray app is not shipped to servers).
apt-get install -y -q --no-install-recommends \
bash ca-certificates ccache clang cmake curl g++ git llvm make meson ninja-build pkg-config python3 \
libbpf-dev libssl-dev libyara-dev nlohmann-json3-dev libcurl4-openssl-dev libarchive-dev libzstd-dev \
procps util-linux iproute2
# Version contract: a tag build publishes only when meson.build, the tag and the built binary agree.
# scripts/release.sh bumps meson.build in the release commit; CI never rewrites the version.
src_version=$(sed -n "s/^ version: '\(.*\)',$/\1/p" meson.build | head -1)
if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
tag_version=${GITHUB_REF_NAME#v}
if [ "$src_version" != "$tag_version" ]; then
echo "meson.build version $src_version does not match tag $GITHUB_REF_NAME; cut releases with scripts/release.sh" >&2
exit 1
fi
fi
export CC=gcc CXX=g++
rm -rf builddir
meson setup builddir -Denable_app=disabled -Denable_tests=true
nice -n 19 ninja -C builddir -j"$jobs"
nice -n 19 meson test -C builddir --print-errorlogs --num-processes "$jobs"
for f in builddir/src/strawberry builddir/src/process_monitor.bpf.o; do
test -s "$f" || { echo "missing build output: $f" >&2; exit 1; }
done
built_version=$(builddir/src/strawberry version | awk '{print $2}')
if [ "$built_version" != "$src_version" ]; then
echo "built binary reports $built_version, meson.build says $src_version" >&2
exit 1
fi
if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
version=$tag_version
else
version="${src_version}+g$(git rev-parse --short=12 HEAD)"
fi
arch=$(dpkg --print-architecture)
name="strawberry-${version}-${os}-${arch}.tgz"
# The pinned rule snapshot packed below must match its reviewed manifest.
if [ -f packaging/rules-snapshot/SNAPSHOT ]; then
(cd packaging/rules-snapshot && sha256sum -c MANIFEST.sha256 --quiet)
fi
mkdir -p "$out"
epoch=$(git log -1 --format=%ct)
# Reproducible-ish archive: fixed order, owner and mtime; gzip without a timestamp.
tar --sort=name --owner=0 --group=0 --numeric-owner --mtime="@${epoch}" -cf - \
scripts config packaging builddir/src/strawberry builddir/src/process_monitor.bpf.o \
| gzip -n -9 > "$out/$name"
(cd "$out" && sha256sum "$name" > "$name.sha256")
echo "built $out/$name"
cat "$out/$name.sha256"