| 1 | name: Reusable Linux desktop and Debian package |
| 2 | on: |
| 3 | workflow_call: |
| 4 | inputs: |
| 5 | ref: |
| 6 | description: Exact 40-character commit SHA to build |
| 7 | required: true |
| 8 | type: string |
| 9 | release: |
| 10 | description: Produce a release candidate without test reports |
| 11 | type: boolean |
| 12 | default: false |
| 13 | artifact_name: |
| 14 | description: Name of the package artifact |
| 15 | required: true |
| 16 | type: string |
| 17 | permissions: |
| 18 | contents: read |
| 19 | jobs: |
| 20 | debian: |
| 21 | |
| 22 | |
| 23 | runs-on: ubuntu-22.04 |
| 24 | timeout-minutes: 60 |
| 25 | defaults: |
| 26 | run: |
| 27 | shell: bash |
| 28 | container: |
| 29 | image: ubuntu:22.04 |
| 30 | |
| 31 | |
| 32 | options: --init --security-opt seccomp=unconfined --security-opt systempaths=unconfined --security-opt apparmor=unconfined |
| 33 | steps: |
| 34 | - name: Install build and test dependencies |
| 35 | run: | |
| 36 | apt-get update |
| 37 | DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev libjson-glib-dev dpkg-dev curl ca-certificates git software-properties-common qemu-system-x86 qemu-utils ovmf openssh-client iproute2 dbus-x11 xvfb xauth fonts-noto-cjk zsh sudo tzdata |
| 38 | # The supported 22.04 ABI predates safe.bareRepository. Use the Git |
| 39 | # project's documented Ubuntu packages, preserving the runtime gate. |
| 40 | add-apt-repository -y ppa:git-core/ppa |
| 41 | apt-get update |
| 42 | DEBIAN_FRONTEND=noninteractive apt-get install -y git |
| 43 | dpkg --compare-versions "$(git --version | awk '{print $3}')" ge 2.38 |
| 44 | useradd -m -s /bin/bash cage |
| 45 | echo "cage ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/cage |
| 46 | - uses: actions/checkout@v4 |
| 47 | with: |
| 48 | ref: ${{ inputs.ref }} |
| 49 | persist-credentials: false |
| 50 | - name: Verify the immutable build revision |
| 51 | env: |
| 52 | CAGE_BUILD_REF: ${{ inputs.ref }} |
| 53 | CAGE_RELEASE: ${{ inputs.release }} |
| 54 | run: | |
| 55 | # checkout's temporary HOME does not persist into later container |
| 56 | # steps. Trust this CI-owned checkout only, before root builds it. |
| 57 | git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 58 | [[ "$CAGE_BUILD_REF" =~ ^[0-9a-fA-F]{40}$ ]] || { echo 'Build ref must be a complete commit SHA.' >&2; exit 1; } |
| 59 | [[ "$(git rev-parse HEAD)" == "${CAGE_BUILD_REF,,}" ]] || { echo 'Checkout differs from the requested commit.' >&2; exit 1; } |
| 60 | if [[ "$CAGE_RELEASE" == true && "$GITHUB_EVENT_NAME" != workflow_dispatch ]]; then |
| 61 | echo 'Release candidates require an explicitly dispatched release workflow.' >&2 |
| 62 | exit 1 |
| 63 | fi |
| 64 | - uses: actions/setup-go@v5 |
| 65 | with: |
| 66 | go-version-file: go.mod |
| 67 | - uses: actions/setup-node@v4 |
| 68 | with: |
| 69 | node-version: 24 |
| 70 | cache: npm |
| 71 | cache-dependency-path: ui/package-lock.json |
| 72 | - uses: astral-sh/[email protected] |
| 73 | - name: Build Linux application and package |
| 74 | run: | |
| 75 | node scripts/check-version.mjs |
| 76 | bash scripts/build-linux.sh |
| 77 | bash scripts/package-linux.sh --skip-build |
| 78 | npm test --prefix ui |
| 79 | npm run --prefix ui lint |
| 80 | node --test internal/cage/browser-clipboard.test.mjs internal/cage/native-input.test.mjs internal/cage/display-density.test.mjs |
| 81 | - name: Linux executable tests as an ordinary user |
| 82 | env: |
| 83 | UV_CACHE_DIR: /home/cage/.cache/uv |
| 84 | UV_PYTHON_INSTALL_DIR: /home/cage/.local/share/uv/python |
| 85 | UV_PYTHON: '3.11' |
| 86 | run: | |
| 87 | chown -R cage:cage "$GITHUB_WORKSPACE" |
| 88 | # uv's setup step runs as root; its cache and managed Python must not |
| 89 | # leak into ordinary-user tests, including tests that isolate HOME. |
| 90 | runuser -u cage -- uv python install 3.11 |
| 91 | runuser -u cage -- go test ./internal/... ./cmd/... |
| 92 | runuser -u cage -- go vet ./internal/managedproxy ./internal/workbench ./cmd/cage |
| 93 | runuser -u cage -- uv run --no-project --python 3.11 internal/cage/desktop-downloads.test.py |
| 94 | runuser -u cage -- uv run --no-project --python 3.11 internal/cage/display-governor.test.py |
| 95 | - name: Ubuntu guest browser, extensions and noVNC dependencies |
| 96 | run: runuser -u cage -- bash scripts/test-ubuntu-guest.sh |
| 97 | - name: Install, render native workbench, reinstall and remove |
| 98 | run: | |
| 99 | runuser -u cage -- bwrap --unshare-user --unshare-pid --ro-bind / / --proc /proc --dev /dev -- true |
| 100 | version=$(cat VERSION) |
| 101 | bash scripts/test-linux-install.sh "_output/releases/$version/linux/Cage-$version-linux-amd64.deb" |
| 102 | - name: Record release candidate identity |
| 103 | if: ${{ inputs.release }} |
| 104 | run: | |
| 105 | version=$(cat VERSION) |
| 106 | node scripts/release-version.mjs metadata linux "_output/releases/$version/linux/build-metadata.json" |
| 107 | - name: Upload verified package and corresponding source |
| 108 | uses: actions/upload-artifact@v4 |
| 109 | with: |
| 110 | name: ${{ inputs.artifact_name }} |
| 111 | path: | |
| 112 | _output/releases/*/linux/Cage-*-linux-amd64.deb |
| 113 | _output/releases/*/linux/SHA256SUMS |
| 114 | _output/releases/*/linux/mihomo-*-source.tar.gz |
| 115 | _output/releases/*/linux/build-metadata.json |
| 116 | if-no-files-found: error |
| 117 | overwrite: true |
| 118 | retention-days: 14 |
| 119 | - name: Preserve public development test reports |
| 120 | if: ${{ always() && !inputs.release }} |
| 121 | uses: actions/upload-artifact@v4 |
| 122 | with: |
| 123 | name: ${{ inputs.artifact_name }}-reports |
| 124 | path: | |
| 125 | /home/cage-package-test/reports/install.json |
| 126 | /home/cage-package-test/reports/first-install.json |
| 127 | /home/cage-package-test/reports/first-install.json.png |
| 128 | /home/cage-package-test/reports/after-reinstall.json |
| 129 | /home/cage-package-test/reports/after-reinstall.json.png |
| 130 | if-no-files-found: ignore |
| 131 | overwrite: true |
| 132 | retention-days: 14 |
| 133 | |
| 134 | |
| 135 | package-compatibility: |
| 136 | needs: debian |
| 137 | runs-on: ubuntu-22.04 |
| 138 | timeout-minutes: 30 |
| 139 | strategy: |
| 140 | fail-fast: false |
| 141 | matrix: |
| 142 | image: [debian:12, ubuntu:24.04] |
| 143 | container: |
| 144 | image: ${{ matrix.image }} |
| 145 | options: --security-opt seccomp=unconfined --security-opt systempaths=unconfined --security-opt apparmor=unconfined |
| 146 | steps: |
| 147 | - name: Install package test tools |
| 148 | run: | |
| 149 | apt-get update |
| 150 | DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates git dbus-x11 xvfb xauth fonts-noto-cjk |
| 151 | - uses: actions/checkout@v4 |
| 152 | with: |
| 153 | ref: ${{ inputs.ref }} |
| 154 | persist-credentials: false |
| 155 | - uses: actions/setup-node@v4 |
| 156 | with: |
| 157 | node-version: 24 |
| 158 | - uses: actions/download-artifact@v4 |
| 159 | with: |
| 160 | name: ${{ inputs.artifact_name }} |
| 161 | path: _output/compatibility |
| 162 | - name: Test the Ubuntu 22.04-built package unchanged |
| 163 | shell: bash |
| 164 | run: | |
| 165 | package=$(find _output/compatibility -name 'Cage-*-linux-amd64.deb' -print -quit) |
| 166 | test -n "$package" |
| 167 | bash scripts/test-linux-install.sh "$package" |