diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..167b265 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Shell scripts must keep LF endings so they run on Linux CI runners even +# when the tree is checked out or edited on Windows. +*.sh text eol=lf +ci/ci-setup.sh text eol=lf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64ab42b..6fbfdff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,33 +1,108 @@ -name: Build and Test +# ============================================================================= +# Multi-Architecture Build & Test Workflow for cpdb-libs +# +# Matrix: 4 architectures. +# amd64, arm64 (native runners); armhf, riscv64 (QEMU) +# +# cpdb-libs is the CUPS-independent D-Bus IPC layer, so there is no CUPS +# matrix here - only the four architectures. All per-leg work lives in +# ci/ci-setup.sh so the legs differ only in whether they run under emulation. +# ============================================================================= +name: Build and Test (cpdb-libs, Multi-Architecture) on: push: branches: - - '**' + - '**' pull_request: branches: - - '**' + - '**' workflow_dispatch: - + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - build-linux-run-tests: + build-matrix: + name: Build & Test (${{ matrix.arch }}) + runs-on: ${{ matrix.runs-on }} + # Emulated legs are slow; give them plenty of headroom. + timeout-minutes: 120 - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + arch: [amd64, arm64, armhf, riscv64] + include: + - arch: amd64 + runs-on: ubuntu-latest + use-qemu: false + - arch: arm64 + runs-on: ubuntu-24.04-arm + use-qemu: false + - arch: armhf + runs-on: ubuntu-latest + use-qemu: true + qemu-arch: armv7 + - arch: riscv64 + runs-on: ubuntu-latest + use-qemu: true + qemu-arch: riscv64 steps: - - uses: actions/checkout@v6 - - name: show Ubuntu version - run: cat /etc/os-release | grep PRETTY_NAME | awk -F '=' '{print $2}' - - name: update build environment - run: sudo apt-get update --fix-missing -y - - name: install prerequisites - run: | - sudo apt-get install -y autoconf autopoint libglib2.0-dev libdbus-1-dev libtool - - name: configure - env: - CC: /usr/bin/gcc - run: ./autogen.sh && ./configure - - name: make - run: make - - name: Run Tests - run: make check || cat test/error_log* + - uses: actions/checkout@v4 + + # ========================================== + # NATIVE EXECUTION (amd64 and arm64) + # ========================================== + - name: Build & Test (Native) + if: matrix.use-qemu == false + run: | + set -ex + sh ci/ci-setup.sh deps + sh ci/ci-setup.sh build + + - name: Upload test artifacts (Native) + if: matrix.use-qemu == false && always() + continue-on-error: true + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: cpdb-libs-logs-${{ matrix.arch }} + path: | + config.log + test-suite.log + tools/*.log + if-no-files-found: ignore + + # ========================================== + # EMULATED EXECUTION (armhf and riscv64) + # ========================================== + - name: Build & Test (Emulated) + if: matrix.use-qemu == true + uses: uraimo/run-on-arch-action@v3 + with: + arch: ${{ matrix.qemu-arch }} + distro: ubuntu24.04 + githubToken: ${{ github.token }} + install: | + apt-get update --fix-missing -y + DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata ca-certificates git + run: | + set -ex + sh ci/ci-setup.sh deps + sh ci/ci-setup.sh build + + - name: Upload test artifacts (Emulated) + if: matrix.use-qemu == true && always() + continue-on-error: true + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: cpdb-libs-logs-${{ matrix.arch }} + path: | + config.log + test-suite.log + tools/*.log + if-no-files-found: ignore diff --git a/ci/ci-setup.sh b/ci/ci-setup.sh new file mode 100755 index 0000000..cd93caa --- /dev/null +++ b/ci/ci-setup.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# ci/ci-setup.sh +# +# CI helper for building and testing cpdb-libs across several CPU +# architectures on both native and QEMU-emulated runners. +# +# cpdb-libs is the D-Bus IPC layer shared by the CPDB frontends and backends +# and MUST NOT depend on CUPS, so there is no CUPS matrix here: the same +# source is exercised only on the four architectures. All per-leg work lives +# in this script so the workflow legs differ only in whether they run under +# emulation. +# +# Subcommands: +# deps install build/test dependencies +# build autogen + configure + make + make check +# +# The script runs as root inside emulation containers and via sudo on native +# runners; it detects which automatically. +set -eu + +SUDO="" +[ "$(id -u)" -eq 0 ] || SUDO="sudo" + +# Make apt completely non-interactive. Native GitHub runners ship +# needrestart, whose service-restart prompt otherwise hangs the job forever; +# the emulated containers do not have it, which is why only the native legs +# stalled. +export DEBIAN_FRONTEND=noninteractive +export NEEDRESTART_MODE=a +export NEEDRESTART_SUSPEND=1 + +apt_install() { + $SUDO apt-get update --fix-missing -y + $SUDO apt-get install -y "$@" +} + +cmd_deps() { + apt_install \ + build-essential autoconf automake libtool libtool-bin pkg-config \ + gettext autopoint autotools-dev git make gcc \ + libglib2.0-dev libdbus-1-dev dbus +} + +cmd_build() { + ./autogen.sh + ./configure + make -j"$(nproc)" V=1 + # run-tests.sh drives the text frontend inside a private session D-Bus. + make check V=1 VERBOSE=1 \ + || { test -f test-suite.log && cat test-suite.log; \ + cat tools/*.log 2>/dev/null; exit 1; } +} + +case "${1:-}" in + deps) cmd_deps ;; + build) cmd_build ;; + *) + echo "usage: ci-setup.sh {deps | build}" >&2 + exit 2 ;; +esac