From ffb01f4d4ffa77a0257ea27dd31238b66221d939 Mon Sep 17 00:00:00 2001 From: JoshiCodes <55353244+JoshiCodes@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:30:47 +0100 Subject: [PATCH] CI: fit the arm64 runner, cross-compile amd64 packages - Job containers request 2 CPUs and install node before checkout - deb and rpm for amd64 are cross-compiled on Ubuntu 22.04 arm64 with multiarch libraries, checked for architecture, contents and glibc level, uploaded as artifacts and attached to tagged releases --- .gitea/workflows/ci.yml | 131 +++++++++++++++++++++++++++++++--------- 1 file changed, 103 insertions(+), 28 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 477cc2f..c4bbfad 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -5,49 +5,124 @@ on: branches: [main] tags: ['v*'] pull_request: + workflow_dispatch: + +# The runner is arm64 with 2 CPUs. Job containers ask for at most that many, +# and JavaScript actions need node inside the container, so it comes first. jobs: test: runs-on: ubuntu-latest - container: rust:1-bookworm + container: + image: rust:1-bookworm + options: --cpus 2 steps: + - name: Install node and build dependencies + run: | + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs \ + libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev librsvg2-dev libdbus-1-dev pkg-config - uses: actions/checkout@v4 - - run: apt-get update && apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev librsvg2-dev libdbus-1-dev pkg-config - run: cargo test -p knock-core --locked - # The oldest supported Ubuntu builds the .deb, so glibc and WebKitGTK fit 22.04 and newer. - deb: + # amd64 packages, cross-compiled on the arm64 runner. Ubuntu 22.04 is the + # oldest supported target, so glibc and WebKitGTK fit 22.04 and newer. + # No AppImage: its tooling only runs on amd64. + packages: needs: test - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest - container: ubuntu:22.04 + container: + image: ubuntu:22.04 + options: --cpus 2 + env: + DEBIAN_FRONTEND: noninteractive + TARGET: x86_64-unknown-linux-gnu + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc + CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc + CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++ + AR_x86_64_unknown_linux_gnu: x86_64-linux-gnu-ar + PKG_CONFIG_ALLOW_CROSS: '1' + PKG_CONFIG_SYSROOT_DIR: / + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig steps: - - uses: actions/checkout@v4 - - run: | + - name: Install node + run: | apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y curl build-essential pkg-config file \ - libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev libdbus-1-dev libssl-dev + apt-get install -y curl ca-certificates gnupg git curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y nodejs - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal - - run: | - . "$HOME/.cargo/env" - npm ci - cargo build --release -p knock-cli --locked - npx tauri build --bundles deb,rpm,appimage - - name: Smoke test on Ubuntu 22.04 + + - uses: actions/checkout@v4 + + - name: Add amd64 as a foreign architecture run: | - apt-get install -y ./target/release/bundle/deb/*.deb xvfb python3 - python3 -m http.server 18765 >/dev/null 2>&1 & - mkdir -p /tmp/c/environments - printf 'version: 1\nname: Smoke\n' > /tmp/c/knock.yaml - printf 'name: Root\nurl: http://127.0.0.1:18765/\nassert:\n - { on: status, equals: 200 }\n' > /tmp/c/root.yaml - knock run /tmp/c - timeout 10 xvfb-run -a knock-app || [ $? -eq 124 ] + # arm64 comes from ports.ubuntu.com, amd64 from the main archive. + sed -i -E 's/^deb (http)/deb [arch=arm64] \1/' /etc/apt/sources.list + cat > /etc/apt/sources.list.d/amd64.list <<'EOF' + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse + EOF + dpkg --add-architecture amd64 + apt-get update + + - name: Install cross toolchain and amd64 libraries + run: | + apt-get install -y build-essential pkg-config file cmake \ + gcc-x86-64-linux-gnu g++-x86-64-linux-gnu libc6-dev-amd64-cross \ + libwebkit2gtk-4.1-dev:amd64 libgtk-3-dev:amd64 libsoup-3.0-dev:amd64 \ + libjavascriptcoregtk-4.1-dev:amd64 librsvg2-dev:amd64 libdbus-1-dev:amd64 + + - name: Install Rust + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --target "$TARGET" + echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" + + - name: Build + run: | + npm ci + cargo build --release --locked -p knock-cli --target "$TARGET" + BIN="../target/$TARGET/release/knock" + npx tauri build --target "$TARGET" --bundles deb,rpm \ + --config "{\"bundle\":{\"linux\":{\"deb\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}},\"rpm\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}}}}}" + + - name: Check packages + run: | + OUT="target/$TARGET/release/bundle" + DEB=$(ls $OUT/deb/*.deb) + dpkg-deb --field "$DEB" Architecture | grep -qx amd64 + dpkg-deb -c "$DEB" | grep -q './usr/bin/knock-app$' + dpkg-deb -c "$DEB" | grep -q './usr/bin/knock$' + dpkg-deb -c "$DEB" | grep -q 'applications/.*\.desktop$' + file "target/$TARGET/release/knock-app" | grep -q 'x86-64' + file "target/$TARGET/release/knock" | grep -q 'x86-64' + # Nothing newer than Ubuntu 22.04's glibc (2.35) may be required. + too_new=$(x86_64-linux-gnu-objdump -T "target/$TARGET/release/knock-app" | grep -oE 'GLIBC_2\.[0-9]+' | sort -u | awk -F. '$2 > 35') + if [ -n "$too_new" ]; then echo "needs newer glibc than Ubuntu 22.04: $too_new"; exit 1; fi + ls -la $OUT/deb $OUT/rpm + - uses: actions/upload-artifact@v3 with: - name: bundles + name: packages-amd64 path: | - target/release/bundle/deb/*.deb - target/release/bundle/rpm/*.rpm - target/release/bundle/appimage/*.AppImage + target/x86_64-unknown-linux-gnu/release/bundle/deb/*.deb + target/x86_64-unknown-linux-gnu/release/bundle/rpm/*.rpm + + - name: Attach to release + if: startsWith(github.ref, 'refs/tags/v') + env: + TOKEN: ${{ secrets.GITEA_TOKEN }} + API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} + TAG: ${{ github.ref_name }} + run: | + apt-get install -y jq + id=$(curl -fsS -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r .id || true) + if [ -z "$id" ] || [ "$id" = "null" ]; then + pre=$(case "$TAG" in *-*) echo true;; *) echo false;; esac) + id=$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \ + -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"prerelease\":$pre}" "$API/releases" | jq -r .id) + fi + for f in target/$TARGET/release/bundle/deb/*.deb target/$TARGET/release/bundle/rpm/*.rpm; do + curl -fsS -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" "$API/releases/$id/assets?name=$(basename "$f")" + done