diff --git a/.github/CI.md b/.github/CI.md index 0829dd6a..7277c5ea 100644 --- a/.github/CI.md +++ b/.github/CI.md @@ -21,15 +21,19 @@ The Ubuntu job uses a disposable OpenPGP identity to publish a local testing RPR and checks pacman install, update and signature rejection. It assembles the system root, disk and online installer, then runs a two-generation signed kernel upgrade and verifies boot confirmation, -module reload and fallback. The job uploads the exact media for smoke -tests and retains failing upgrade logs. +module reload and fallback. It applies the update once, then runs the +BIOS and UEFI checks concurrently on private disk overlays. Each firmware +boots the new kernel before the previous one, and attempts the unconfirmed +slot before checking automatic fallback on a separate overlay. ## Boot and status -BIOS and UEFI jobs download the same media, start the online installer -and boot the assembled system as systemd PID 1. The smoke checks cover +The Ubuntu job also boots the generated ISO and disk locally on BIOS and +UEFI in parallel. The smoke checks cover the online installer, systemd PID 1, merged-usr, packages, ext4 and the ESP, core services and boot confirmation. -QEMU jobs retain serial logs and result records. +The job verifies the checksums around the smoke tests and uploads the tested +media once for download. QEMU serial logs and result records are available +as separate artifacts. Select **CI result** as the required branch check. It reports every required job and treats a missing or failed result as a failure. @@ -38,8 +42,11 @@ required job and treats a missing or failed result as a failure. A successful CI result for a push to `main` triggers the production publisher. To retry from Actions, run **ReliefOS CI** on `main` with **publish_pages** -enabled. The workflow builds the verified commit, serializes production -deployments, and skips commits already deployed or superseded on `main`. +enabled. The publisher takes the tested unsigned packages and installer +tools from the same CI run and checks their commit and SHA-256 before use. +The publisher signs a production repository and assembles an ISO against +it. The workflow serializes deployments and skips commits already deployed +or superseded on `main`. Configure the `github-pages` environment for `main` deployments. Set the `RPR_SIGNING_FINGERPRINT` Actions variable to the primary fingerprint from diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 782c0312..b5596af1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,12 +84,12 @@ jobs: tools/build/arch-rootfs{,-install}.sh tools/build/arch-guest-packages.sh \ tools/build/glibc-runtime-headers.sh userland/apps/installer/arch-online-install.sh \ system/installer/installer-session \ - tools/build/arch-rpr-{sign,trust,kernel-check}.sh \ + tools/build/arch-rpr-{sign,trust,kernel-check,package-check}.sh \ tests/integration/arch-{runtime,kernel,boot}-package.sh tests/integration/arch-boot-hook.sh \ tests/integration/arch-rpr-{testing,pacman}.sh \ tests/integration/arch-{kernel-prune,kernel-prune-container,systemd-boot,systemd-entry}.sh \ tests/integration/arch-kernel-upgrade{,-build}.sh - shellcheck scripts/ci/{restore-rpr,publish-pages}.sh + shellcheck scripts/ci/{pages-inputs,restore-rpr,publish-pages}.sh /usr/bin/python3 -m unittest discover -s tools/tests -p 'test_ci*.py' -v documentation: @@ -138,6 +138,8 @@ jobs: if: needs.changes.outputs.build == 'true' runs-on: ubuntu-24.04 timeout-minutes: 120 + env: + ARCH_JOBS: '4' strategy: fail-fast: false matrix: @@ -219,16 +221,31 @@ jobs: - name: Compose the BIOS and UEFI disk if: matrix.host == 'ubuntu-24.04' run: make O=out/ci-arch-root image-vmdk + - name: Boot the installer and installed system on BIOS and UEFI + if: matrix.host == 'ubuntu-24.04' + run: bash scripts/ci/smoke.sh out/ci-arch-root - name: Verify signed kernel upgrades, module reload and boot fallback if: matrix.host == 'ubuntu-24.04' env: - ARCH_JOBS: '2' RELIEFOS_QMP_DIR: ${{ runner.temp }} TMPDIR: /dev/shm - run: bash tests/integration/arch-kernel-upgrade-build.sh out/ci-arch-root - - name: Record and upload the exact products for boot verification - if: matrix.host == 'ubuntu-24.04' - run: python3 tools/ci.py manifest --root out/ci-arch-root + run: bash tests/integration/arch-kernel-upgrade-build.sh out/ci-arch-root --parallel-firmwares + - name: Pack the verified release inputs + if: >- + matrix.host == 'ubuntu-24.04' && github.ref == 'refs/heads/main' && + (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish_pages)) + id: pack_release + run: bash scripts/ci/pages-inputs.sh pack out/ci-arch-root "$RUNNER_TEMP/release-inputs" + - name: Upload the verified release inputs + if: steps.pack_release.outcome == 'success' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: reliefos-release-inputs-${{ github.sha }} + path: ${{ runner.temp }}/release-inputs/ + if-no-files-found: error + compression-level: 1 + overwrite: true + retention-days: 7 - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: matrix.host == 'ubuntu-24.04' with: @@ -240,6 +257,7 @@ jobs: out/ci-arch-root/ci/manifest.json if-no-files-found: error compression-level: 0 + overwrite: true retention-days: 3 - name: Preserve signed upgrade evidence if: ${{ !cancelled() && matrix.host == 'ubuntu-24.04' }} @@ -248,45 +266,23 @@ jobs: name: reliefos-arch-upgrade-${{ github.sha }} path: out/ci-arch-root/ci/arch-kernel-upgrade if-no-files-found: ignore + overwrite: true retention-days: 3 - - smoke: - name: Arch products (${{ matrix.firmware }}) - needs: arch_root - runs-on: ubuntu-24.04 - timeout-minutes: 35 - strategy: - fail-fast: false - matrix: - firmware: [bios, uefi] - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Check out the ReliefNT boot probe source - run: git submodule update --init --depth 1 -- kernel/reliefnt - - uses: ./.github/actions/setup - with: - profile: smoke - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: reliefos-images-${{ github.sha }} - path: out/ci-arch-root - - name: Boot the online installer and installed system - env: - SMOKE_FIRMWARE: ${{ matrix.firmware }} - run: bash scripts/ci/smoke.sh out/ci-arch-root - - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - if: ${{ !cancelled() }} + - name: Preserve BIOS and UEFI boot evidence + if: ${{ !cancelled() && matrix.host == 'ubuntu-24.04' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: reliefos-boot-${{ matrix.firmware }}-${{ github.sha }} - path: out/ci-smoke/${{ matrix.firmware }} + name: reliefos-boot-${{ github.sha }} + path: | + out/ci-smoke/bios + out/ci-smoke/uefi if-no-files-found: ignore + overwrite: true retention-days: 3 ci: name: CI result - needs: [changes, checks, documentation, regressions, arch_root, smoke] + needs: [changes, checks, documentation, regressions, arch_root] if: always() runs-on: ubuntu-24.04 timeout-minutes: 5 diff --git a/.github/workflows/publish-pages.yml b/.github/workflows/publish-pages.yml index 38a82301..3873f8f3 100644 --- a/.github/workflows/publish-pages.yml +++ b/.github/workflows/publish-pages.yml @@ -25,7 +25,7 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} env: ARCH_BASE_REGISTRY: docker.io - ARCH_JOBS: '2' + ARCH_JOBS: '4' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -65,12 +65,19 @@ jobs: python-version: '3.12' cache: pip cache-dependency-path: Documentation/requirements.txt - - name: Install Sphinx and build release packages + - name: Download the tested build inputs from this CI run + if: steps.current.outputs.publish == 'true' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: reliefos-release-inputs-${{ github.sha }} + path: ${{ runner.temp }}/release-inputs + - name: Prepare the release environment and verify the build inputs if: steps.current.outputs.publish == 'true' shell: bash run: | python -m pip install -r Documentation/requirements.txt 'Sphinx==9.*' - bash scripts/ci/arch-host.sh ubuntu-24.04 out/production-pages + make O=out/production-pages fetch + bash scripts/ci/pages-inputs.sh restore out/production-pages "$RUNNER_TEMP/release-inputs" - name: Sign the repository with the production subkey if: steps.current.outputs.publish == 'true' id: signed diff --git a/scripts/ci/arch-host.sh b/scripts/ci/arch-host.sh index d5bead2e..8ff58077 100644 --- a/scripts/ci/arch-host.sh +++ b/scripts/ci/arch-host.sh @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends docker-cli git && rm -rf /var/lib/apt/lists/* DOCKERFILE launcher=(docker run --rm -i --pull=never --user "$(id -u):$(id -g)" - --group-add "$(stat -c %g /var/run/docker.sock)" --env HOME=/tmp --env ARCH_BASE_REGISTRY + --group-add "$(stat -c %g /var/run/docker.sock)" --env HOME=/tmp --env ARCH_BASE_REGISTRY --env ARCH_JOBS --mount 'type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock' --mount "type=bind,src=$PWD,dst=$PWD" --workdir "$PWD" reliefos-ci-debian) ;; @@ -23,6 +23,6 @@ DOCKERFILE esac "${launcher[@]}" bash -eu -s -- "$output" <<'BUILD' for goal in doctor fetch build; do - make O="$1" ARCH_JOBS=2 "$goal" + make O="$1" "$goal" done BUILD diff --git a/scripts/ci/pages-inputs.sh b/scripts/ci/pages-inputs.sh new file mode 100644 index 00000000..c41d3c50 --- /dev/null +++ b/scripts/ci/pages-inputs.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Transfer the tested unsigned packages and installer tools within this CI run. +set -euo pipefail +operation=${1:?pack or restore required} +output=$(realpath -e -- "${2:?Arch build output required}") +handoff=$(realpath -m -- "${3:?artifact directory required}") +commit=$(git rev-parse --verify HEAD) +fail() { printf 'pages-inputs: %s\n' "$*" >&2; exit 1; } +[[ ${GITHUB_SHA:-$commit} == "$commit" ]] || fail 'checkout differs from the workflow commit' +[[ -f $output/.reliefos-arch-root ]] || fail 'Arch build output is not initialized' + +case $operation in + pack) + mkdir -p -- "$handoff" + cd -- "$output" + shopt -s nullglob + packages=(packages/arch/*.pkg.tar.zst) + pointers=(packages/arch/*-current) + (( ${#packages[@]} && ${#pointers[@]} )) || fail 'the package set is empty' + for file in "${packages[@]}" "${pointers[@]}"; do + [[ -s $file && -f $file && ! -L $file ]] || fail "invalid package input $file" + done + tar -cf "$handoff/inputs.tar" -- "${packages[@]}" "${pointers[@]}" \ + host/bin/reliefos-kernel-tools grub-host/bin grub-host/lib/grub/i386-pc \ + grub-efi/bin/grub-mkstandalone grub-efi/lib/grub/x86_64-efi + sha256sum < "$handoff/inputs.tar" > "$handoff/inputs.sha256" + printf '%s\n' "$commit" > "$handoff/source-commit" + ;; + restore) + [[ $(<"$handoff/source-commit") == "$commit" ]] || fail 'build artifact belongs to a different commit' + digest=$(sha256sum < "$handoff/inputs.tar") + [[ $digest == "$(<"$handoff/inputs.sha256")" ]] || fail 'build artifact checksum mismatch' + tar -xf "$handoff/inputs.tar" --no-same-owner -C "$output" + ;; + *) fail "unknown action $operation" ;; +esac diff --git a/scripts/ci/smoke.sh b/scripts/ci/smoke.sh index f2a94637..b1175a21 100644 --- a/scripts/ci/smoke.sh +++ b/scripts/ci/smoke.sh @@ -1,22 +1,39 @@ #!/usr/bin/env bash set -euo pipefail -root=${1:?verified artifact root required} -firmware=${SMOKE_FIRMWARE:-} -case "$firmware" in - bios) systemd_options=(--direct-root) ;; - uefi) systemd_options=() ;; - *) echo 'SMOKE_FIRMWARE must be bios or uefi' >&2; exit 2 ;; +root=${1:?local Arch build output required} +firmwares=${SMOKE_FIRMWARE:-both} +case "$firmwares" in + bios|uefi|both) ;; + *) echo 'SMOKE_FIRMWARE must be bios, uefi or both' >&2; exit 2 ;; esac -python3 tools/ci.py verify --root "$root" +python3 tools/ci.py manifest --root "$root" export RELIEFOS_QMP_DIR=${RUNNER_TEMP:-/tmp} -output=out/ci-smoke/$firmware -mkdir -p "$output" -probe=$output/systemd-compat-probe +mkdir -p out/ci-smoke +probe=out/ci-smoke/systemd-compat-probe cc -static -O2 -Wall -Wextra -Werror \ kernel/reliefnt/tools/tests/systemd_compat_runtime_probe.c -o "$probe" -python3 tools/test_arch_installer_iso.py --iso "$root/images/reliefos-installer.iso" \ - --firmware "$firmware" --output "$output/installer" --timeout 600 -python3 tools/test_arch_systemd_qemu.py --disk "$root/images/reliefos.vmdk" \ - --firmwares "$firmware" "${systemd_options[@]}" --output "$output/systemd" --timeout 600 \ - --guest-check tests/integration/arch-systemd-compat.sh --guest-file "$probe" + +boot_products() { + local firmware=$1 output=out/ci-smoke/$1 + local -a systemd_options=() + if [[ $firmware == bios ]]; then systemd_options+=(--direct-root); fi + python3 tools/test_arch_installer_iso.py --iso "$root/images/reliefos-installer.iso" \ + --firmware "$firmware" --output "$output/installer" --timeout 600 + python3 tools/test_arch_systemd_qemu.py --disk "$root/images/reliefos.vmdk" \ + --firmwares "$firmware" "${systemd_options[@]}" --output "$output/systemd" --timeout 600 \ + --guest-check tests/integration/arch-systemd-compat.sh --guest-file "$probe" +} + +status=0 +if [[ $firmwares == both ]]; then + boot_products bios & + bios=$! + boot_products uefi & + uefi=$! + wait "$bios" || status=$? + wait "$uefi" || status=$? +else + boot_products "$firmwares" +fi python3 tools/ci.py verify --root "$root" +exit "$status" diff --git a/tests/integration/arch-kernel-upgrade-build.sh b/tests/integration/arch-kernel-upgrade-build.sh index de5715d9..3e8deab1 100644 --- a/tests/integration/arch-kernel-upgrade-build.sh +++ b/tests/integration/arch-kernel-upgrade-build.sh @@ -2,11 +2,12 @@ # Build a second signed kernel generation for the real-disk upgrade gate. set -euo pipefail source_root=$(realpath -e -- "$(dirname -- "$0")/../..") -if (( $# != 1 )); then - printf 'usage: %s ARCH_OUTPUT\n' "$0" >&2 +if (( $# < 1 || $# > 2 )) || [[ $# == 2 && $2 != --parallel-firmwares ]]; then + printf 'usage: %s ARCH_OUTPUT [--parallel-firmwares]\n' "$0" >&2 exit 2 fi output=$(realpath -e -- "$1") +shift [[ -f $output/.reliefos-arch-root && -f $output/images/reliefos.raw ]] mkdir -p -- "$output/ci/arch-kernel-upgrade" evidence=$(mktemp -d "$output/ci/arch-kernel-upgrade/run.XXXXXXXX") @@ -59,4 +60,4 @@ test -s "$work/arch-kernel/stage/usr/lib/modules/$new_release/kernel/drivers/sto python3 "$source_root/tools/test_arch_kernel_upgrade_qemu.py" \ --disk "$output/images/reliefos.raw" --snapshot "$work/rpr-testing/$snapshot" \ --fingerprint "$RPR_SIGNING_FINGERPRINT" --old-release "$old_release" --new-release "$new_release" \ - --timeout 600 --output "$evidence/boot" + --timeout 600 --output "$evidence/boot" "$@" diff --git a/tests/integration/arch-systemd-entry.sh b/tests/integration/arch-systemd-entry.sh index b201579f..6829c819 100644 --- a/tests/integration/arch-systemd-entry.sh +++ b/tests/integration/arch-systemd-entry.sh @@ -4,9 +4,19 @@ set -euo pipefail exec > /dev/console 2>&1 trap 'printf "[arch-test] failed line=%s status=%s\n" "$LINENO" "$?"' ERR +action= +for argument in $(&2; exit 1; } + +[[ $(pacman -Qp -- "$runtime") == "libreliefos $runtime_version" ]] || + fail 'runtime package metadata disagrees with its filename' +if [[ -n $previous_runtime_version ]]; then + previous_runtime=../previous-runtime.pkg.tar.zst + [[ $(pacman -Qp -- "$previous_runtime") == "libreliefos $previous_runtime_version" ]] || + fail 'previous runtime package metadata disagrees with its filename' + comparison=$(vercmp "$runtime_version" "$previous_runtime_version") + [[ $comparison != -1 ]] || fail 'runtime package version is older than the previous snapshot' + if [[ $comparison == 0 ]]; then + cmp -s -- "$previous_runtime" "$runtime" || + fail 'runtime package version has different contents from the previous snapshot' + fi +fi + +for contract in "$@"; do + IFS='|' read -r name archive version glibc_only previous_version <<< "$contract" + [[ $(pacman -Qp -- "$archive") == "$name $version" ]] || + fail "$name package metadata disagrees with its filename" + app_metadata=$(bsdtar -xOf "$archive" .PKGINFO) || fail "cannot read $name package metadata" + mapfile -t app_runtime_dependencies < <(printf '%s\n' "$app_metadata" | + awk '/^depend = libreliefos([<>=]|$)/ {sub(/^depend = /, ""); print}') + if [[ $glibc_only == 1 ]]; then + if [[ ${#app_runtime_dependencies[@]} != 0 ]] || ! grep -Fxq 'depend = glibc' <<< "$app_metadata"; then + fail "$name package must depend on glibc directly" + fi + else + app_dependency_pattern='^libreliefos>=([0-9][A-Za-z0-9._+]*)-([0-9]+(\.[0-9]+)?)$' + [[ ${#app_runtime_dependencies[@]} == 1 && ${app_runtime_dependencies[0]} =~ $app_dependency_pattern ]] || + fail "$name package lacks a valid minimum runtime dependency" + app_runtime_version=${BASH_REMATCH[1]}-${BASH_REMATCH[2]} + comparison=$(vercmp "$runtime_version" "$app_runtime_version") + [[ $comparison != -1 ]] || fail "$name package requires a newer runtime" + fi + if [[ -n $previous_version ]]; then + previous_archive=../previous-$name.pkg.tar.zst + [[ $(pacman -Qp -- "$previous_archive") == "$name $previous_version" ]] || + fail "previous $name package metadata disagrees with its filename" + comparison=$(vercmp "$version" "$previous_version") + [[ $comparison != -1 ]] || fail "$name package version is older than the previous snapshot" + if [[ $comparison == 0 ]]; then + cmp -s -- "$previous_archive" "$archive" || + fail "$name package version has different contents from the previous snapshot" + fi + fi +done + +[[ $(pacman -Qp -- "$boot") == "reliefos-boot 1.$boot_sequence-1" ]] || + fail 'boot package metadata disagrees with its filename' +boot_metadata=$(bsdtar -xOf "$boot" .PKGINFO) || fail 'cannot read boot package metadata' +mapfile -t boot_arches < <(printf '%s\n' "$boot_metadata" | sed -n 's/^arch = //p') +[[ ${#boot_arches[@]} == 1 && ${boot_arches[0]} == "$boot_arch" ]] || + fail 'boot package architecture disagrees with its filename' +if [[ $boot_arch == x86_64 ]]; then + mapfile -t boot_runtime_dependencies < <(printf '%s\n' "$boot_metadata" | + awk '/^depend = libreliefos([<>=]|$)/ {sub(/^depend = /, ""); print}') + boot_dependency_pattern='^libreliefos>=([0-9][A-Za-z0-9._+]*)-([0-9]+(\.[0-9]+)?)$' + [[ ${#boot_runtime_dependencies[@]} == 1 && ${boot_runtime_dependencies[0]} =~ $boot_dependency_pattern ]] || + fail 'boot package lacks a valid minimum runtime dependency' + boot_runtime_version=${BASH_REMATCH[1]}-${BASH_REMATCH[2]} + comparison=$(vercmp "$runtime_version" "$boot_runtime_version") + [[ $comparison != -1 ]] || fail 'boot package requires a newer runtime' +fi diff --git a/tools/build/arch-rpr-sign.sh b/tools/build/arch-rpr-sign.sh index b72844a5..23e0a4c2 100644 --- a/tools/build/arch-rpr-sign.sh +++ b/tools/build/arch-rpr-sign.sh @@ -117,7 +117,7 @@ parent=$output/rpr-testing mkdir -p -- "$parent" pointer=$parent/current-$fingerprint previous_update= -previous_runtime= +previous_runtime_version= previous= kernel_archives=() if [[ -e $pointer || -L $pointer ]]; then @@ -138,7 +138,6 @@ if [[ -e $pointer || -L $pointer ]]; then previous_runtime_version=${BASH_REMATCH[1]}-${BASH_REMATCH[2]} gpgv --homedir "$work/verify" --keyring "$public" -- "${previous_runtimes[0]}.sig" "${previous_runtimes[0]}" cp -- "${previous_runtimes[0]}" "$work/previous-runtime.pkg.tar.zst" - previous_runtime=/rpr-work/previous-runtime.pkg.tar.zst for name in "${app_packages[@]}"; do previous_apps=("$previous"/"$name"-*-x86_64.pkg.tar.zst) (( ${#previous_apps[@]} <= 1 )) || fail "previous snapshot has multiple $name packages" @@ -202,67 +201,16 @@ arch() { --mount "type=bind,src=$work,dst=/rpr-work,bind-recursive=disabled" \ --mount "type=bind,src=$source_root/packages/arch/reliefos-keyring,dst=/keyring,readonly,bind-recursive=disabled" \ --mount "type=bind,src=$source_root/tools/build/arch-rpr-kernel-check.sh,dst=/kernel-check.sh,readonly" \ + --mount "type=bind,src=$source_root/tools/build/arch-rpr-package-check.sh,dst=/package-check.sh,readonly" \ --workdir /rpr-work/site "$image" "$@" } arch bash /kernel-check.sh "$payload" "$update" "$previous_update" "${kernel_archives[@]}" -[[ $(arch pacman -Qp -- "/rpr-work/site/$runtime") == "libreliefos $runtime_version" ]] || - fail 'runtime package metadata disagrees with its filename' -if [[ -n $previous_runtime ]]; then - [[ $(arch pacman -Qp -- "$previous_runtime") == "libreliefos $previous_runtime_version" ]] || - fail 'previous runtime package metadata disagrees with its filename' - comparison=$(arch vercmp "$runtime_version" "$previous_runtime_version") - [[ $comparison != -1 ]] || fail 'runtime package version is older than the previous snapshot' - if [[ $comparison == 0 ]]; then - cmp -s -- "$work/previous-runtime.pkg.tar.zst" "$output/packages/arch/$runtime" || - fail 'runtime package version has different contents from the previous snapshot' - fi -fi +app_contracts=() for name in "${app_packages[@]}"; do - [[ $(arch pacman -Qp -- "/rpr-work/site/${app_archives[$name]}") == "$name ${app_versions[$name]}" ]] || - fail "$name package metadata disagrees with its filename" - app_metadata=$(arch bsdtar -xOf "/rpr-work/site/${app_archives[$name]}" .PKGINFO) || - fail "cannot read $name package metadata" - mapfile -t app_runtime_dependencies < <(printf '%s\n' "$app_metadata" | - awk '/^depend = libreliefos([<>=]|$)/ {sub(/^depend = /, ""); print}') - if [[ ${glibc_only[$name]:-} == 1 ]]; then - if [[ ${#app_runtime_dependencies[@]} != 0 ]] || ! grep -Fxq 'depend = glibc' <<< "$app_metadata"; then - fail "$name package must depend on glibc directly" - fi - else - app_dependency_pattern='^libreliefos>=([0-9][A-Za-z0-9._+]*)-([0-9]+(\.[0-9]+)?)$' - [[ ${#app_runtime_dependencies[@]} == 1 && ${app_runtime_dependencies[0]} =~ $app_dependency_pattern ]] || - fail "$name package lacks a valid minimum runtime dependency" - app_runtime_version=${BASH_REMATCH[1]}-${BASH_REMATCH[2]} - [[ $(arch vercmp "$runtime_version" "$app_runtime_version") != -1 ]] || - fail "$name package requires a newer runtime" - fi - if [[ -n ${previous_app_versions[$name]:-} ]]; then - [[ $(arch pacman -Qp -- "/rpr-work/previous-$name.pkg.tar.zst") == "$name ${previous_app_versions[$name]}" ]] || - fail "previous $name package metadata disagrees with its filename" - comparison=$(arch vercmp "${app_versions[$name]}" "${previous_app_versions[$name]}") - [[ $comparison != -1 ]] || fail "$name package version is older than the previous snapshot" - if [[ $comparison == 0 ]]; then - cmp -s -- "$work/previous-$name.pkg.tar.zst" "$output/packages/arch/${app_archives[$name]}" || - fail "$name package version has different contents from the previous snapshot" - fi - fi + app_contracts+=("$name|${app_archives[$name]}|${app_versions[$name]}|${glibc_only[$name]:-0}|${previous_app_versions[$name]:-}") done -[[ $(arch pacman -Qp -- "/rpr-work/site/$boot") == "reliefos-boot 1.$boot_sequence-1" ]] || - fail 'boot package metadata disagrees with its filename' -boot_metadata=$(arch bsdtar -xOf "/rpr-work/site/$boot" .PKGINFO) || fail 'cannot read boot package metadata' -mapfile -t boot_arches < <(printf '%s\n' "$boot_metadata" | sed -n 's/^arch = //p') -[[ ${#boot_arches[@]} == 1 && ${boot_arches[0]} == "$boot_arch" ]] || - fail 'boot package architecture disagrees with its filename' -if [[ $boot_arch == x86_64 ]]; then - mapfile -t boot_runtime_dependencies < <(printf '%s\n' "$boot_metadata" | - awk '/^depend = libreliefos([<>=]|$)/ {sub(/^depend = /, ""); print}') - boot_dependency_pattern='^libreliefos>=([0-9][A-Za-z0-9._+]*)-([0-9]+(\.[0-9]+)?)$' - [[ ${#boot_runtime_dependencies[@]} == 1 && ${boot_runtime_dependencies[0]} =~ $boot_dependency_pattern ]] || - fail 'boot package lacks a valid minimum runtime dependency' - boot_runtime_version=${BASH_REMATCH[1]}-${BASH_REMATCH[2]} - comparison=$(arch vercmp "$runtime_version" "$boot_runtime_version") - [[ $comparison != -1 ]] || fail 'boot package requires a newer runtime' -fi +arch bash /package-check.sh "$runtime" "$runtime_version" "$previous_runtime_version" \ + "$boot" "$boot_sequence" "$boot_arch" "${app_contracts[@]}" arch env "SOURCE_DATE_EPOCH=$(git -C "$source_root" show -s --format=%ct "$source_commit")" \ RELIEFOS_KEYRING_DIR=/rpr-work \ makepkg --dir /keyring --nocolor --nosign \ diff --git a/tools/ci.py b/tools/ci.py index b88596a9..cf44704c 100644 --- a/tools/ci.py +++ b/tools/ci.py @@ -22,7 +22,7 @@ "tools/build/docs-page.sh", "tools/test_documentation.py", ".github/workflows/check-docs.yml", ".github/workflows/ci.yml", ".github/actions/", ) -STAGES = ("changes", "checks", "documentation", "regressions", "arch_root", "smoke") +STAGES = ("changes", "checks", "documentation", "regressions", "arch_root") def matches(path, patterns): @@ -135,7 +135,7 @@ def summary(needs): if outputs.get("docs") == "true": required.add("documentation") if outputs.get("build") == "true": - required.update(("regressions", "arch_root", "smoke")) + required.update(("regressions", "arch_root")) passed = valid_scope and set(needs) == set(STAGES) lines = ["## ReliefOS CI", "", "| Stage | Required | Result |", "| --- | --- | --- |"] for name in STAGES: diff --git a/tools/test_arch_kernel_upgrade_qemu.py b/tools/test_arch_kernel_upgrade_qemu.py index 318998de..892918fc 100644 --- a/tools/test_arch_kernel_upgrade_qemu.py +++ b/tools/test_arch_kernel_upgrade_qemu.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Upgrade a real Arch disk from signed RPR and boot new, previous and fallback kernels.""" import argparse +from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from functools import partial from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer @@ -8,9 +9,11 @@ from pathlib import Path import re import shlex +from shutil import copyfile import subprocess from tempfile import TemporaryDirectory import threading +import time from test_arch_systemd_qemu import ROOT, boot, create_overlay, launch_system, serial_text, stage_grub_boot, wait_for @@ -34,6 +37,7 @@ def log_message(self, format, *arguments): def run_phase(args, firmware, output, fixture, overlay, action): """Check a boot, then freeze its synced state before QEMU closes the overlay.""" + started = time.monotonic() extra = "systemd.mask=reliefos-boot-confirm.service" if action == "unconfirmed" else "" direct_root = action == "upgrade" stage_grub_boot(fixture, previous=action == "previous", extra_arguments=extra, @@ -53,20 +57,25 @@ def run_phase(args, firmware, output, fixture, overlay, action): assert "Kernel Panic" not in text and "KERNEL PANIC" not in text, "Kernel panic" probe.key("ctrl-alt-f1") probe.command("stop") - print(json.dumps({"firmware": firmware, "phase": action, "passed": True}), flush=True) + print(json.dumps({"firmware": firmware, "phase": action, "passed": True, + "seconds": round(time.monotonic() - started, 1)}), flush=True) def verify_boots(args, firmware, output, fixture, upgraded, scratch): """Start both boot branches from the same untried, committed transaction.""" with TemporaryDirectory(prefix=f"{firmware}-", dir=scratch) as directory: - successful = Path(directory) / "successful.qcow2" - failed = Path(directory) / "unconfirmed.qcow2" + work = Path(directory) + # stage_grub_boot rewrites the guest command file on every boot. + checks = work / "checks.fat" + copyfile(fixture, checks) + successful = work / "successful.qcow2" + failed = work / "unconfirmed.qcow2" create_overlay(upgraded, successful, backing_format="qcow2") create_overlay(upgraded, failed, backing_format="qcow2") - run_phase(args, firmware, output / "new", fixture, successful, "new") - run_phase(args, firmware, output / "previous", fixture, successful, "previous") - run_phase(args, firmware, output / "unconfirmed", fixture, failed, "unconfirmed") - run_phase(args, firmware, output / "fallback", fixture, failed, "fallback") + run_phase(args, firmware, output / "new", checks, successful, "new") + run_phase(args, firmware, output / "previous", checks, successful, "previous") + run_phase(args, firmware, output / "unconfirmed", checks, failed, "unconfirmed") + run_phase(args, firmware, output / "fallback", checks, failed, "fallback") def verify(args, firmwares, output, fixture): @@ -90,14 +99,22 @@ def record(result): record({"firmware": first, "phase": "upgrade", "passed": False, "error": str(error)}) return results - for firmware in firmwares: + def check(firmware): result = {"firmware": firmware, "passed": False} try: verify_boots(args, firmware, output / firmware, fixture, upgraded, scratch) result["passed"] = True except Exception as error: result["error"] = str(error) - record(result) + return result + + if args.parallel_firmwares: + with ThreadPoolExecutor(max_workers=2) as workers: + for result in workers.map(check, firmwares): + record(result) + else: + for firmware in firmwares: + record(check(firmware)) return results @@ -111,6 +128,8 @@ def main(): parser.add_argument("--output", type=Path, required=True) parser.add_argument("--screenshot", type=Path) parser.add_argument("--firmwares", default="bios,uefi") + parser.add_argument("--parallel-firmwares", action="store_true", + help="run the independent post-upgrade firmware checks concurrently") parser.add_argument("--firmware-image", type=Path) parser.add_argument("--accel", choices=("auto", "kvm", "tcg"), default="auto") parser.add_argument("--timeout", type=int, default=300, @@ -127,8 +146,11 @@ def main(): if args.old_release == args.new_release: parser.error("use two distinct kernel releases") firmwares = args.firmwares.split(",") - if any(firmware not in ("bios", "uefi") for firmware in firmwares): - parser.error("--firmwares must contain bios and/or uefi") + if (len(set(firmwares)) != len(firmwares) or + any(firmware not in ("bios", "uefi") for firmware in firmwares)): + parser.error("--firmwares must contain bios and/or uefi once") + if args.parallel_firmwares and args.screenshot: + parser.error("--screenshot requires sequential firmware checks") args.output = args.output.resolve() args.output.mkdir(parents=True, exist_ok=False) if args.screenshot: diff --git a/tools/tests/test_ci.py b/tools/tests/test_ci.py index a3e22c2e..53f24386 100644 --- a/tools/tests/test_ci.py +++ b/tools/tests/test_ci.py @@ -141,12 +141,55 @@ def test_symlinked_input_is_rejected(self): +class ReleaseInputsTests(unittest.TestCase): + def test_round_trip_and_reject_mismatched_release_inputs(self): + checkout = Path(ci.__file__).resolve().parents[1] + script = checkout / "scripts/ci/pages-inputs.sh" + with tempfile.TemporaryDirectory() as directory: + work = Path(directory) + source, target, handoff = (work / name for name in ("source", "target", "handoff")) + for root in (source, target): + root.mkdir() + (root / ".reliefos-arch-root").touch() + inputs = ("packages/arch/example-1-1-any.pkg.tar.zst", "packages/arch/example-current", + "host/bin/reliefos-kernel-tools", "grub-host/bin/grub-mkimage", + "grub-host/lib/grub/i386-pc/reliefos.mod", "grub-efi/bin/grub-mkstandalone", + "grub-efi/lib/grub/x86_64-efi/reliefos.mod") + for name in (*inputs, "images/reliefos.raw", "packages/arch/repo.sig"): + path = source / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(name) + (source / "grub-efi/bin/grub-mkstandalone").chmod(0o755) + + def run(command, root, *, check=True): + return subprocess.run(["bash", script, command, root, handoff], cwd=checkout, + check=check, capture_output=True, text=True) + + run("pack", source) + run("restore", target) + for name in inputs: + self.assertEqual((target / name).read_text(), name) + self.assertTrue(os.access(target / "grub-efi/bin/grub-mkstandalone", os.X_OK)) + for name in ("images/reliefos.raw", "packages/arch/repo.sig"): + self.assertFalse((target / name).exists()) + + with (handoff / "inputs.tar").open("ab") as archive: + archive.write(b"changed archive") + error = run("restore", target, check=False) + self.assertNotEqual(error.returncode, 0) + self.assertIn("checksum mismatch", error.stderr) + (handoff / "source-commit").write_text("0" * 40 + "\n") + error = run("restore", target, check=False) + self.assertNotEqual(error.returncode, 0) + self.assertIn("different commit", error.stderr) + + class GateTests(unittest.TestCase): def needs(self, build=True, docs=True): result = {name: {"result": "success"} for name in ci.STAGES} result["changes"]["outputs"] = {"build": str(build).lower(), "docs": str(docs).lower()} if not build: - for name in ("arch_root", "regressions", "smoke"): + for name in ("arch_root", "regressions"): result[name]["result"] = "skipped" if not docs: result["documentation"]["result"] = "skipped" diff --git a/tools/tests/test_ci_arch_systemd_harness.py b/tools/tests/test_ci_arch_systemd_harness.py index 5e19da03..ad41ce00 100644 --- a/tools/tests/test_ci_arch_systemd_harness.py +++ b/tools/tests/test_ci_arch_systemd_harness.py @@ -8,6 +8,7 @@ import sys from pathlib import Path from tempfile import TemporaryDirectory +from threading import Barrier from types import SimpleNamespace import unittest from unittest.mock import Mock, call, patch @@ -114,12 +115,14 @@ def test_default_kernel_handoff_fails_before_waiting_for_grub_prompt(self): def test_firmwares_boot_independent_copies_of_one_signed_upgrade(self): with TemporaryDirectory() as directory: work = Path(directory) - args = SimpleNamespace(disk=work / "target.qcow2") + fixture = work / "checks.fat" + fixture.write_text("shared seed") + args = SimpleNamespace(disk=work / "target.qcow2", parallel_firmwares=False) with (patch.object(upgrade, "run_phase") as phase, patch.object(upgrade.subprocess, "check_output", return_value='{"format": "qcow2"}'), patch.object(upgrade.subprocess, "run") as run): - result = upgrade.verify(args, ["bios", "uefi"], work, work / "checks.fat") + result = upgrade.verify(args, ["bios", "uefi"], work, fixture) calls = [call.args for call in phase.call_args_list] self.assertEqual([(call[1], call[-1]) for call in calls], @@ -146,6 +149,39 @@ def test_each_phase_is_started_by_a_boot_service(self): self.assertNotIn("$reliefos_root_policy", command) self.assertNotIn("ctrl-alt-f6", probe.keys) + def test_parallel_upgrade_boots_use_private_fixtures_and_collect_both_results(self): + ready = Barrier(2, timeout=2) + observed = {"bios": [], "uefi": []} + + def run_phase(args, firmware, output, fixture, overlay, action): + if action == "upgrade": + self.assertEqual(observed, {"bios": [], "uefi": []}) + return + self.assertEqual(fixture.read_text(), "shared seed") + observed[firmware].append((fixture, overlay, action)) + if action == "new": + ready.wait() + if firmware == "bios" and action == "fallback": + raise RuntimeError("BIOS failed") + + with TemporaryDirectory() as directory: + work = Path(directory) + fixture = work / "checks.fat" + fixture.write_text("shared seed") + args = SimpleNamespace(disk=work / "target.qcow2", parallel_firmwares=True) + with (patch.object(upgrade, "run_phase", side_effect=run_phase), + patch.object(upgrade, "create_overlay")): + results = upgrade.verify(args, ["bios", "uefi"], work, fixture) + + self.assertEqual(results, [{"firmware": "bios", "passed": False, "error": "BIOS failed"}, + {"firmware": "uefi", "passed": True}]) + self.assertEqual(len({checks for boots in observed.values() for checks, _, _ in boots}), 2) + for boots in observed.values(): + self.assertEqual([action for _, _, action in boots], ["new", "previous", "unconfirmed", "fallback"]) + self.assertEqual(boots[0][1], boots[1][1]) + self.assertEqual(boots[2][1], boots[3][1]) + self.assertNotEqual(boots[0][1], boots[2][1]) + def test_direct_boot_keeps_a_fallback_archive(self): _, commands = self.launch("direct ext4 modules=1", direct_root=True) command = next(line for line in commands if line.startswith("multiboot2 "))