|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + build_aarch64_flatpak: |
| 11 | + description: 'Build aarch64 Flatpak (slow, ~6 hours with QEMU)' |
| 12 | + required: false |
| 13 | + default: false |
| 14 | + type: boolean |
| 15 | + build_riscv64: |
| 16 | + description: 'Build riscv64 debug binary' |
| 17 | + required: false |
| 18 | + default: false |
| 19 | + type: boolean |
| 20 | + |
| 21 | +env: |
| 22 | + CARGO_TERM_COLOR: always |
| 23 | + |
| 24 | +jobs: |
| 25 | + check: |
| 26 | + name: Check & Build |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + fetch-tags: true |
| 34 | + |
| 35 | + - name: Install Rust toolchain |
| 36 | + uses: dtolnay/rust-toolchain@stable |
| 37 | + with: |
| 38 | + components: rustfmt, clippy |
| 39 | + |
| 40 | + - name: Install system dependencies |
| 41 | + run: | |
| 42 | + sudo apt-get update |
| 43 | + sudo apt-get install -y \ |
| 44 | + libgstreamer1.0-dev \ |
| 45 | + libgstreamer-plugins-base1.0-dev \ |
| 46 | + libgstreamer-plugins-bad1.0-dev \ |
| 47 | + gstreamer1.0-plugins-base \ |
| 48 | + gstreamer1.0-plugins-good \ |
| 49 | + gstreamer1.0-plugins-bad \ |
| 50 | + gstreamer1.0-plugins-ugly \ |
| 51 | + gstreamer1.0-libav \ |
| 52 | + libwayland-dev \ |
| 53 | + libxkbcommon-dev \ |
| 54 | + libinput-dev \ |
| 55 | + libudev-dev \ |
| 56 | + libseat-dev |
| 57 | +
|
| 58 | + - name: Install just |
| 59 | + uses: extractions/setup-just@v2 |
| 60 | + |
| 61 | + - name: Cache cargo registry |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: | |
| 65 | + ~/.cargo/registry |
| 66 | + ~/.cargo/git |
| 67 | + target |
| 68 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 69 | + restore-keys: | |
| 70 | + ${{ runner.os }}-cargo- |
| 71 | +
|
| 72 | + - name: Check formatting |
| 73 | + run: just fmt-check |
| 74 | + |
| 75 | + - name: Run cargo check |
| 76 | + run: just cargo-check |
| 77 | + |
| 78 | + - name: Run tests |
| 79 | + run: just test |
| 80 | + |
| 81 | + - name: Build release |
| 82 | + run: just build-release |
| 83 | + |
| 84 | + # Cross-compiled debug builds to verify compilation on all target architectures |
| 85 | + # x86_64 and aarch64 always run; riscv64 runs on main or manual trigger |
| 86 | + build-x86_64: |
| 87 | + name: Build (x86_64) |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: check |
| 90 | + steps: |
| 91 | + - name: Checkout repository |
| 92 | + uses: actions/checkout@v4 |
| 93 | + with: |
| 94 | + fetch-depth: 0 |
| 95 | + fetch-tags: true |
| 96 | + |
| 97 | + - name: Install Rust toolchain |
| 98 | + uses: dtolnay/rust-toolchain@stable |
| 99 | + with: |
| 100 | + targets: x86_64-unknown-linux-gnu |
| 101 | + |
| 102 | + - name: Install system dependencies |
| 103 | + run: | |
| 104 | + sudo apt-get update |
| 105 | + sudo apt-get install -y \ |
| 106 | + libgstreamer1.0-dev \ |
| 107 | + libgstreamer-plugins-base1.0-dev \ |
| 108 | + libgstreamer-plugins-bad1.0-dev \ |
| 109 | + libwayland-dev \ |
| 110 | + libxkbcommon-dev \ |
| 111 | + libinput-dev \ |
| 112 | + libudev-dev \ |
| 113 | + libseat-dev |
| 114 | +
|
| 115 | + - name: Build debug binary |
| 116 | + run: cargo build --target x86_64-unknown-linux-gnu |
| 117 | + |
| 118 | + build-aarch64: |
| 119 | + name: Build (aarch64) |
| 120 | + runs-on: ubuntu-latest |
| 121 | + needs: check |
| 122 | + steps: |
| 123 | + - name: Checkout repository |
| 124 | + uses: actions/checkout@v4 |
| 125 | + with: |
| 126 | + fetch-depth: 0 |
| 127 | + fetch-tags: true |
| 128 | + |
| 129 | + - name: Install Rust toolchain |
| 130 | + uses: dtolnay/rust-toolchain@stable |
| 131 | + with: |
| 132 | + targets: aarch64-unknown-linux-gnu |
| 133 | + |
| 134 | + - name: Install cross |
| 135 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 136 | + |
| 137 | + - name: Build debug binary |
| 138 | + run: cross build --target aarch64-unknown-linux-gnu |
| 139 | + |
| 140 | + build-riscv64: |
| 141 | + name: Build (riscv64) |
| 142 | + runs-on: ubuntu-latest |
| 143 | + needs: check |
| 144 | + # Run on push to main, or on manual trigger with build_riscv64=true |
| 145 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.build_riscv64) |
| 146 | + steps: |
| 147 | + - name: Checkout repository |
| 148 | + uses: actions/checkout@v4 |
| 149 | + with: |
| 150 | + fetch-depth: 0 |
| 151 | + fetch-tags: true |
| 152 | + |
| 153 | + - name: Install Rust toolchain |
| 154 | + uses: dtolnay/rust-toolchain@stable |
| 155 | + with: |
| 156 | + targets: riscv64gc-unknown-linux-gnu |
| 157 | + |
| 158 | + - name: Install cross |
| 159 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 160 | + |
| 161 | + - name: Build debug binary |
| 162 | + run: cross build --target riscv64gc-unknown-linux-gnu |
| 163 | + |
| 164 | + # Flatpak build times (using QEMU emulation for non-x86_64): |
| 165 | + # |
| 166 | + # | Architecture | Duration | |
| 167 | + # |--------------|---------------------| |
| 168 | + # | x86_64 | ~20 minutes | |
| 169 | + # | aarch64 | ~5 hours 47 minutes | |
| 170 | + # | riscv64 | failed immediately | |
| 171 | + # |
| 172 | + # The aarch64 build uses QEMU emulation on an x86_64 runner, which is extremely |
| 173 | + # slow (compiling Rust under emulation). |
| 174 | + # |
| 175 | + # Options for native ARM64 runners: |
| 176 | + # 1. GitHub's ARM runners (runs-on: ubuntu-24.04-arm64) - requires GitHub Team/Enterprise or larger runners (paid) |
| 177 | + # 2. Self-hosted runner - free, but you need your own ARM hardware |
| 178 | + # 3. Disable aarch64 for now - build locally when needed |
| 179 | + # |
| 180 | + # aarch64: Runs on push to main, but on PRs only when manually triggered via workflow_dispatch |
| 181 | + # riscv64 disabled: Flathub doesn't provide org.freedesktop.Platform runtime for riscv64 |
| 182 | + flatpak-x86_64: |
| 183 | + name: Flatpak (x86_64) |
| 184 | + runs-on: ubuntu-latest |
| 185 | + needs: check |
| 186 | + steps: |
| 187 | + - name: Checkout repository |
| 188 | + uses: actions/checkout@v4 |
| 189 | + with: |
| 190 | + fetch-depth: 0 |
| 191 | + fetch-tags: true |
| 192 | + |
| 193 | + - name: Install Flatpak and flatpak-builder |
| 194 | + run: | |
| 195 | + sudo apt-get update |
| 196 | + sudo apt-get install -y flatpak flatpak-builder |
| 197 | +
|
| 198 | + - name: Add Flathub remote |
| 199 | + run: | |
| 200 | + sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo |
| 201 | +
|
| 202 | + - name: Install Flatpak SDK and runtime |
| 203 | + run: | |
| 204 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=x86_64 |
| 205 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=x86_64 |
| 206 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=x86_64 |
| 207 | +
|
| 208 | + - name: Install just |
| 209 | + uses: extractions/setup-just@v2 |
| 210 | + |
| 211 | + - name: Install Python dependencies for cargo-sources generator |
| 212 | + run: | |
| 213 | + pip install aiohttp toml tomlkit |
| 214 | +
|
| 215 | + - name: Build Flatpak bundle |
| 216 | + run: just flatpak-bundle-arch x86_64 |
| 217 | + |
| 218 | + - name: Upload Flatpak bundle |
| 219 | + uses: actions/upload-artifact@v4 |
| 220 | + with: |
| 221 | + name: cosmic-camera-x86_64.flatpak |
| 222 | + path: cosmic-camera-x86_64.flatpak |
| 223 | + retention-days: 7 |
| 224 | + |
| 225 | + flatpak-aarch64: |
| 226 | + name: Flatpak (aarch64) |
| 227 | + runs-on: ubuntu-latest |
| 228 | + needs: check |
| 229 | + # Run on push to main, or on manual trigger with build_aarch64_flatpak=true |
| 230 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.build_aarch64_flatpak) |
| 231 | + steps: |
| 232 | + - name: Checkout repository |
| 233 | + uses: actions/checkout@v4 |
| 234 | + with: |
| 235 | + fetch-depth: 0 |
| 236 | + fetch-tags: true |
| 237 | + |
| 238 | + - name: Install Flatpak and flatpak-builder |
| 239 | + run: | |
| 240 | + sudo apt-get update |
| 241 | + sudo apt-get install -y flatpak flatpak-builder |
| 242 | +
|
| 243 | + - name: Set up QEMU for multi-arch builds |
| 244 | + uses: docker/setup-qemu-action@v3 |
| 245 | + with: |
| 246 | + platforms: arm64 |
| 247 | + |
| 248 | + - name: Add Flathub remote |
| 249 | + run: | |
| 250 | + sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo |
| 251 | +
|
| 252 | + - name: Install Flatpak SDK and runtime |
| 253 | + run: | |
| 254 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Platform//24.08 --arch=aarch64 |
| 255 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk//24.08 --arch=aarch64 |
| 256 | + sudo flatpak install -y --noninteractive flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 --arch=aarch64 |
| 257 | +
|
| 258 | + - name: Install just |
| 259 | + uses: extractions/setup-just@v2 |
| 260 | + |
| 261 | + - name: Install Python dependencies for cargo-sources generator |
| 262 | + run: | |
| 263 | + pip install aiohttp toml tomlkit |
| 264 | +
|
| 265 | + - name: Build Flatpak bundle |
| 266 | + run: just flatpak-bundle-arch aarch64 |
| 267 | + |
| 268 | + - name: Upload Flatpak bundle |
| 269 | + uses: actions/upload-artifact@v4 |
| 270 | + with: |
| 271 | + name: cosmic-camera-aarch64.flatpak |
| 272 | + path: cosmic-camera-aarch64.flatpak |
| 273 | + retention-days: 7 |
0 commit comments