#!/usr/bin/env bash # End-to-end test: builds the package "demo" in deb, rpm and arch, runs release.sh in test mode with a # throwaway keys, mounts the signed tree into containers and installs the package with apt, dnf, pacman and apk. # Needs docker and network access to pull images. Nothing is published. set -Eeuo pipefail SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd -P) ROOT_DIR="$(dirname "$SCRIPT_DIR")" # shellcheck source=scripts/lib.sh source "${ROOT_DIR}/scripts/lib.sh" work=$(mktemp -d) cleanup() { trap - SIGINT SIGHUP SIGTERM SIGQUIT ERR EXIT rm -rf "$work" return 0 } # shellcheck disable=SC2154 # rc is assigned inside the trap string itself trap 'rc=$?; cleanup; exit $rc' SIGINT SIGHUP SIGTERM SIGQUIT ERR EXIT docker build -q -f "${ROOT_DIR}/build/Dockerfile.sign" -t r4ven-pkgs-sign "${ROOT_DIR}/build" > /dev/null docker build -q -f "${ROOT_DIR}/build/Dockerfile.apk" -t r4ven-pkgs-apk "${ROOT_DIR}/build" > /dev/null mkdir "${work}/fixtures" "${work}/gnupg" chmod 700 "${work}/gnupg" docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp \ -v "${SCRIPT_DIR}/make_fixtures.sh:/make_fixtures.sh:ro" -v "${work}/fixtures:/out" \ r4ven-pkgs-sign /make_fixtures.sh /out > /dev/null 2>&1 # apk fixtures (unsigned), then one SHA256SUMS for all formats docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp \ -v "${SCRIPT_DIR}/make_apk_fixtures.sh:/make_apk_fixtures.sh:ro" -v "${work}/fixtures:/out" \ r4ven-pkgs-apk /make_apk_fixtures.sh /out (cd "${work}/fixtures" && rm -f SHA256SUMS && sha256sum ./* | sed 's|\./||' > SHA256SUMS) # An EC P-256 key, like the real r4ven-apk key openssl ecparam -name prime256v1 -genkey -noout -out "${work}/apk.pem" openssl pkey -in "${work}/apk.pem" -pubout -out "${work}/apk.pub" export GNUPGHOME="${work}/gnupg" gpg --batch -q --passphrase '' --quick-generate-key "pkgs test" rsa3072 sign 1y 2> /dev/null fingerprint=$(gpg --list-keys --with-colons | awk -F: '/^fpr:/ {print $10; exit}') gpg --armor --export-secret-keys "$fingerprint" > "${work}/private.asc" gpg --armor --export "$fingerprint" > "${work}/public.asc" unset GNUPGHOME APK_PUBLIC_KEY="${work}/apk.pub" APK_KEY_FILE="${work}/apk.pem" PUBLIC_KEY="${work}/public.asc" KEY_FILE="${work}/private.asc" SRC="${work}/fixtures" \ SITE_DIR="${work}/site" DRY_RUN=1 "${ROOT_DIR}/scripts/release.sh" r4ven-me/demo v1.0.3 2>&1 | grep -v GPG_TTY # The checks before signing: the packages must come from the tagged commit of a clean checkout, and the tag must be # on the Forgejo (the address is unreachable here, so the last case stops at the API). proj="${work}/proj" git init -q "$proj" printf 'dist/\n' > "${proj}/.gitignore" git_proj() { git -C "$proj" -c user.name=test -c user.email=test@example.org "$@"; } mkdir "${proj}/dist" && cp "${work}/fixtures"/* "${proj}/dist/" git_proj add .gitignore && git_proj commit -q -m first && git_proj tag v1.0.0 expect_stop() { local expected="$1" tag="$2" src="$3" err if err=$(SRC="$src" FORGEJO_URL=https://127.0.0.1:1 FORGEJO_TOKEN=x SITE_REMOTE=user@host:/srv/pkgs \ PUBLIC_KEY="${work}/public.asc" KEY_FILE="${work}/private.asc" SITE_DIR="${work}/site-negative" \ "${ROOT_DIR}/scripts/release.sh" r4ven-me/demo "$tag" 2>&1); then log_error "release.sh must fail: ${expected}" fi grep -q "$expected" <<< "$err" || log_error "Expected '${expected}', got: ${err}" [[ ! -e "${work}/site-negative" ]] || log_error "The run went on after the check: ${expected}" } expect_stop 'not inside a git checkout' v1.0.0 "${work}/fixtures" expect_stop 'is not in the checkout' v9.9.9 "${proj}/dist" printf 'x\n' > "${proj}/file" && git_proj add file && git_proj commit -q -m second expect_stop 'is not at the tag' v1.0.0 "${proj}/dist" git_proj tag v2.0.0 printf 'y\n' >> "${proj}/file" expect_stop 'uncommitted changes' v2.0.0 "${proj}/dist" git_proj checkout -q -- file expect_stop 'Tag v2.0.0 is not found' v2.0.0 "${proj}/dist" # Four versions went in, KEEP=3 must leave three per format. for pattern in 'deb/pool/*/*/*/*.deb' 'rpm/x86_64/*.rpm' 'arch/x86_64/*.pkg.tar.zst' 'apk/25.12/x86_64/*.apk'; do count=$(find "${work}/site" -path "${work}/site/${pattern}" | wc -l) [[ "$count" -eq 3 ]] || log_error "Expected 3 files for ${pattern}, found ${count}" done [[ -f "${work}/site/index.html" ]] || log_error "No index.html" # A .sha256 file next to every package (3 per format), and each must match the published file. sums=$(find "${work}/site" -name '*.sha256' | wc -l) [[ "$sums" -eq 12 ]] || log_error "Expected 12 .sha256 files, found ${sums}" while IFS= read -r sum_file; do (cd "$(dirname "$sum_file")" && sha256sum --check --quiet "$(basename "$sum_file")") || log_error "Checksum mismatch: ${sum_file}" done < <(find "${work}/site" -name '*.sha256') grep -q "$(cut -d' ' -f1 "${work}/site/arch/x86_64/demo-1.0.3-1-x86_64.pkg.tar.zst.sha256")" "${work}/site/index.html" || log_error "The landing page has no checksum" # The signed release files are the source of the checksums for the Forgejo release body: # 12 packages, 3 Arch .sig, SHA256SUMS and its signature. signed="${ROOT_DIR}/.work/releases/r4ven-me_demo_v1.0.3/signed" count=$(find "$signed" -type f | wc -l) [[ "$count" -eq 17 ]] || log_error "Expected 17 release files, found ${count}" (cd "$signed" && sha256sum --check --quiet SHA256SUMS) || log_error "The release files do not match the new SHA256SUMS" mkdir -m 700 "${work}/verify" GNUPGHOME="${work}/verify" gpg --batch -q --import "${work}/public.asc" 2> /dev/null GNUPGHOME="${work}/verify" gpg --batch --verify "${signed}/SHA256SUMS.asc" "${signed}/SHA256SUMS" 2> /dev/null || log_error "SHA256SUMS.asc does not verify" while read -r hash name; do site_sum=$(find "${work}/site" -name "${name}.sha256" | head -n 1) [[ -z "$site_sum" || "$(cut -d' ' -f1 "$site_sum")" == "$hash" ]] || log_error "${name}: release hash differs from the site" done < "${signed}/SHA256SUMS" rpm_file=$(find "$signed" -name '*.rpm' | head -n 1) cmp -s "$rpm_file" "$(find "${work}/site/rpm" -name "$(basename "$rpm_file")")" || log_error "The release rpm differs from the site rpm" cmp -s <(gpg --dearmor < "${work}/public.asc") "${work}/site/r4ven-pkgs.gpg" || log_error "r4ven-pkgs.gpg is not the binary form of the public key" # The clients read the signed tree from a mounted directory (file:// URLs): the signature checks are # the same as over HTTP, and the test needs no network between containers. site_mount=(-v "${work}/site:/srv:ro") log_info "apt" docker run --rm "${site_mount[@]}" -v "${work}/public.asc:/k.asc:ro" debian:13-slim sh -ec ' install -d /etc/apt/keyrings; cp /k.asc /etc/apt/keyrings/r4ven.asc printf "Types: deb\nURIs: file:///srv/deb\nSuites: stable\nComponents: main\nSigned-By: /etc/apt/keyrings/r4ven.asc\n" > /etc/apt/sources.list.d/r4ven.sources apt-get update -qq > /dev/null; apt-get install -y -qq demo > /dev/null; test "$(demo)" = "demo 1.0.3"' log_info "dnf" docker run --rm "${site_mount[@]}" -v "${work}/public.asc:/k.asc:ro" fedora:latest sh -ec ' cp /k.asc /etc/pki/rpm-gpg/r4ven.asc printf "[r4ven]\nname=r4ven\nbaseurl=file:///srv/rpm/\$basearch\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/r4ven.asc\n" > /etc/yum.repos.d/r4ven.repo dnf install -y -q --disablerepo="*" --enablerepo=r4ven demo > /dev/null; test "$(demo)" = "demo 1.0.3"' log_info "pacman" docker run --rm "${site_mount[@]}" -v "${work}/public.asc:/k.asc:ro" archlinux:latest sh -ec ' pacman-key --init > /dev/null 2>&1; pacman-key --add /k.asc 2> /dev/null; pacman-key --lsign-key '"$fingerprint"' > /dev/null 2>&1 printf "[options]\nArchitecture = auto\nSigLevel = Required DatabaseOptional\n[r4ven]\nServer = file:///srv/arch/\$arch\n" > /tmp/p.conf pacman --config /tmp/p.conf --disable-sandbox -Sy --noconfirm demo > /dev/null 2>&1; test "$(demo)" = "demo 1.0.3"' log_info "apk" docker run --rm "${site_mount[@]}" -v "${work}/apk.pub:/k.pub:ro" alpine:3.23 sh -ec ' cp /k.pub /etc/apk/keys/r4ven-apk.pub echo /srv/apk/25.12/x86_64/packages.adb > /etc/apk/repositories apk update > /dev/null; apk add -q demo; test "$(demo)" = "demo 1.0.3" # without the key apk must call the index untrusted (it exits 0 but ignores the index) rm /etc/apk/keys/r4ven-apk.pub; apk update 2>&1 | grep -q "UNTRUSTED signature"' grep -q 'class="chip" href="apk/25.12/x86_64/demo-1.0.3-r0.apk"' "${work}/site/index.html" || log_error "No apk link on the landing page" log_info "All four clients installed demo 1.0.3 with signature checks on"