| 1 | # posprint — BlueGit CI (git.timfalken.com/timfa/posprint). |
| 2 | # Migrated from the old .gitlab-ci.yml (GitLab is now a backup only). |
| 3 | # |
| 4 | # Merge request / any branch push: test. |
| 5 | # Master: test + all release builds + AUR dry run (nothing is published). |
| 6 | # `release` runs automatically after green builds on master: it creates the next tag (highest tag + 1 |
| 7 | # patch, or Cargo.toml if higher; override with RELEASE_VERSION) through the |
| 8 | # BlueGit release API, but only if HEAD is untagged and something outside |
| 9 | # docs/CI changed since the last tag (scripts/ci/release.sh); otherwise it |
| 10 | # writes `skip` and publish:aur does nothing. Release notes: RELEASE_NOTES.md. |
| 11 | # |
| 12 | # BlueGit release API with the build artifacts as assets. Then publish:aur |
| 13 | # updates the AUR packages posprint and posprint-bin. |
| 14 | # Tag pushes never run a pipeline (old tags must not rebuild). |
| 15 | # |
| 16 | # Secrets (repository, protected): AUR_SSH_PRIVATE_KEY_B64, |
| 17 | # AUR_GIT_AUTHOR_NAME, AUR_GIT_AUTHOR_EMAIL. |
| 18 | |
| 19 | stages: [test, build, release, publish] |
| 20 | |
| 21 | variables: |
| 22 | CARGO_TERM_COLOR: always |
| 23 | RUST_BACKTRACE: "1" |
| 24 | CARGO_BUILD_JOBS: "3" |
| 25 | CARGO_PROFILE_DEV_DEBUG: "false" |
| 26 | CARGO_PROFILE_TEST_DEBUG: "false" |
| 27 | |
| 28 | workflow: |
| 29 | rules: |
| 30 | - if: $CI_COMMIT_TAG != "" |
| 31 | when: never |
| 32 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 33 | - if: $CI_COMMIT_BRANCH == "master" |
| 34 | # Temporary experimental branch (TSPL2 label printers), see .experimental. |
| 35 | - if: $CI_COMMIT_BRANCH == "experimental/tspl2" |
| 36 | - if: $CI_PIPELINE_SOURCE == "web" |
| 37 | - if: $CI_PIPELINE_SOURCE == "api" |
| 38 | |
| 39 | .master: |
| 40 | rules: |
| 41 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 42 | when: never |
| 43 | - if: $CI_COMMIT_BRANCH == "master" |
| 44 | |
| 45 | .rust: |
| 46 | image: rust:1.96-bookworm |
| 47 | timeout: 2h |
| 48 | before_script: |
| 49 | - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home" |
| 50 | - export PATH="$CARGO_HOME/bin:$PATH" |
| 51 | - apt-get update -qq |
| 52 | - apt-get install -y -qq libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev libudev-dev libdbus-1-dev pkg-config |
| 53 | |
| 54 | test: |
| 55 | extends: .rust |
| 56 | stage: test |
| 57 | cache: |
| 58 | key: cargo-test |
| 59 | paths: [target/, cargo-home/] |
| 60 | script: |
| 61 | - cargo test --verbose |
| 62 | |
| 63 | version: |
| 64 | rules: |
| 65 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 66 | when: never |
| 67 | - if: $CI_COMMIT_BRANCH == "master" |
| 68 | - if: $CI_PIPELINE_SOURCE == "web" |
| 69 | - if: $CI_PIPELINE_SOURCE == "api" |
| 70 | stage: test |
| 71 | image: bluegit/base |
| 72 | needs: [] |
| 73 | script: |
| 74 | - mkdir -p artifacts |
| 75 | - bash scripts/ci/next-version.sh | tee artifacts/version.txt |
| 76 | artifacts: |
| 77 | paths: [artifacts/version.txt] |
| 78 | expire_in: 14d |
| 79 | |
| 80 | build:linux-deb: |
| 81 | extends: [.rust, .master] |
| 82 | stage: build |
| 83 | needs: [version, test] |
| 84 | cache: |
| 85 | key: cargo-deb |
| 86 | paths: [target/, cargo-home/] |
| 87 | script: |
| 88 | - apt-get install -y -qq dpkg-dev |
| 89 | - cargo install cargo-deb --locked |
| 90 | - bash scripts/ci/set-version.sh |
| 91 | - cargo deb |
| 92 | - mkdir -p dist |
| 93 | - cp target/debian/posprint_$(cat artifacts/version.txt)-1_amd64.deb dist/amd64.deb |
| 94 | artifacts: |
| 95 | # BlueGit artifacts are exact file paths (no globs or directories). |
| 96 | paths: [dist/amd64.deb] |
| 97 | expire_in: 30d |
| 98 | |
| 99 | build:linux-arch: |
| 100 | extends: .master |
| 101 | stage: build |
| 102 | image: archlinux/archlinux:base-devel |
| 103 | timeout: 2h |
| 104 | needs: [version, test] |
| 105 | script: |
| 106 | # BlueGit sets no CI_PROJECT_DIR; jobs start in the checkout. |
| 107 | - export CI_PROJECT_DIR="$PWD" |
| 108 | - pacman -Syu --noconfirm |
| 109 | - pacman -S --noconfirm --needed rust pkgconf openssl libxkbcommon libxcb dbus wayland libx11 fontconfig freetype2 libglvnd git rsync |
| 110 | - bash scripts/ci/set-version.sh |
| 111 | - export PKGVER="$(cat artifacts/version.txt)" |
| 112 | - sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD |
| 113 | - useradd -m builduser |
| 114 | - chown -R builduser:builduser "$CI_PROJECT_DIR" |
| 115 | - su builduser -c "cd $CI_PROJECT_DIR/packaging/arch && makepkg -f --noconfirm" |
| 116 | - mkdir -p "$CI_PROJECT_DIR/dist" |
| 117 | - | |
| 118 | set -euo pipefail |
| 119 | shopt -s nullglob |
| 120 | mains=("$CI_PROJECT_DIR"/packaging/arch/posprint-${PKGVER}-*-x86_64.pkg.tar.zst) |
| 121 | shopt -u nullglob |
| 122 | if [[ ${#mains[@]} -ne 1 ]]; then |
| 123 | echo "Expected one non-debug Arch package, found ${#mains[@]}" >&2 |
| 124 | exit 1 |
| 125 | fi |
| 126 | cp "${mains[0]}" "$CI_PROJECT_DIR/dist/x86_64.pkg.tar.zst" |
| 127 | out="$CI_PROJECT_DIR/dist/x86_64-bin.tar.gz" |
| 128 | bash "$CI_PROJECT_DIR/scripts/make-linux-bin-tarball.sh" "${mains[0]}" "$out" "$PKGVER" |
| 129 | test -s "$out" |
| 130 | artifacts: |
| 131 | paths: [dist/x86_64.pkg.tar.zst, dist/x86_64-bin.tar.gz] |
| 132 | expire_in: 30d |
| 133 | |
| 134 | # Cross-compiled with MinGW (no Windows runner on BlueGit). |
| 135 | build:windows: |
| 136 | extends: [.rust, .master] |
| 137 | stage: build |
| 138 | needs: [version, test] |
| 139 | cache: |
| 140 | key: cargo-windows |
| 141 | paths: [target/, cargo-home/] |
| 142 | before_script: |
| 143 | - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home" |
| 144 | - export PATH="$CARGO_HOME/bin:$PATH" |
| 145 | - apt-get update -qq |
| 146 | - apt-get install -y -qq gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 |
| 147 | - rustup target add x86_64-pc-windows-gnu |
| 148 | # winres calls plain `windres`; use the MinGW one. |
| 149 | - ln -sf /usr/bin/x86_64-w64-mingw32-windres /usr/local/bin/windres |
| 150 | script: |
| 151 | - bash scripts/ci/set-version.sh |
| 152 | - cargo build --release --locked --target x86_64-pc-windows-gnu |
| 153 | - mkdir -p dist |
| 154 | - cp target/x86_64-pc-windows-gnu/release/posprint.exe dist/ |
| 155 | artifacts: |
| 156 | paths: [dist/posprint.exe] |
| 157 | expire_in: 30d |
| 158 | |
| 159 | # Cross-built on Linux (no macOS runner): universal Posprint.app as zip. |
| 160 | # Untested on a real Mac in CI; not notarized. |
| 161 | build:macos: |
| 162 | stage: build |
| 163 | image: ghcr.io/rust-cross/cargo-zigbuild:latest |
| 164 | timeout: 2h |
| 165 | needs: [version, test] |
| 166 | rules: |
| 167 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 168 | when: never |
| 169 | - if: $CI_COMMIT_BRANCH == "master" |
| 170 | # Manual pipeline on a branch: build-check macOS only. |
| 171 | - if: $CI_PIPELINE_SOURCE == "web" |
| 172 | - if: $CI_PIPELINE_SOURCE == "api" |
| 173 | cache: |
| 174 | key: cargo-macos |
| 175 | paths: [target/, cargo-home/] |
| 176 | script: |
| 177 | - export CARGO_HOME="$PWD/cargo-home" PATH="$PWD/cargo-home/bin:$PATH" |
| 178 | - bash scripts/ci/set-version.sh |
| 179 | - bash scripts/ci/build-macos.sh |
| 180 | artifacts: |
| 181 | paths: [dist/macos-universal.zip] |
| 182 | expire_in: 30d |
| 183 | |
| 184 | # Safe AUR check on every master pipeline: real SSH key and AUR clone, |
| 185 | # PKGBUILD/.SRCINFO generation, but AUR_DRY_RUN=1 never pushes. |
| 186 | aur:dry-run: |
| 187 | extends: .master |
| 188 | stage: release |
| 189 | image: archlinux/archlinux:base-devel |
| 190 | needs: [version, build:linux-arch] |
| 191 | allow_failure: true |
| 192 | script: |
| 193 | - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux |
| 194 | - bash scripts/aur-ssh-setup.sh |
| 195 | - last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)" |
| 196 | - export POSPRINT_SOURCE_ARCHIVE_URL="$CI_API_URL/projects/$CI_PROJECT_PATH/repository/tags/$last/archive" |
| 197 | - cp dist/x86_64-bin.tar.gz "dist/posprint-$(cat artifacts/version.txt)-x86_64.tar.gz" |
| 198 | - AUR_DRY_RUN=1 bash scripts/publish-aur.sh "$(cat artifacts/version.txt)" |
| 199 | |
| 200 | release: |
| 201 | extends: .master |
| 202 | stage: release |
| 203 | image: bluegit/base |
| 204 | needs: [version, build:linux-deb, build:linux-arch, build:windows, build:macos] |
| 205 | resource_group: release |
| 206 | script: |
| 207 | - bash scripts/ci/release.sh |
| 208 | artifacts: |
| 209 | paths: [artifacts/released.txt] |
| 210 | expire_in: 30d |
| 211 | |
| 212 | publish:aur: |
| 213 | extends: .master |
| 214 | stage: publish |
| 215 | image: archlinux/archlinux:base-devel |
| 216 | needs: [version, release, build:linux-arch] |
| 217 | allow_failure: true |
| 218 | resource_group: aur |
| 219 | script: |
| 220 | - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux |
| 221 | - bash scripts/aur-ssh-setup.sh |
| 222 | - if [ "$(cat artifacts/released.txt)" = "skip" ]; then echo "No new release in this pipeline; AUR unchanged."; exit 0; fi |
| 223 | - cp dist/x86_64-bin.tar.gz "dist/posprint-$(cat artifacts/version.txt)-x86_64.tar.gz" |
| 224 | - bash scripts/publish-aur.sh "$(cat artifacts/version.txt)" |
| 225 | |
| 226 | # --- Experimental branch experimental/tspl2 only -------------------------- |
| 227 | # Windows + Linux test builds published as ONE BlueGit release with the fixed |
| 228 | # tag `experimental-tspl2` (replaced on every run, never a version tag). |
| 229 | # Never runs on master or merge requests; no AUR, no secrets except the job |
| 230 | # token (and the optional EXPERIMENTAL_RELEASE_TOKEN to replace the release). |
| 231 | .experimental: |
| 232 | rules: |
| 233 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 234 | when: never |
| 235 | - if: $CI_COMMIT_BRANCH == "experimental/tspl2" |
| 236 | |
| 237 | exp:version: |
| 238 | extends: .experimental |
| 239 | stage: test |
| 240 | image: bluegit/base |
| 241 | needs: [] |
| 242 | script: |
| 243 | - bash scripts/ci/experimental-version.sh |
| 244 | artifacts: |
| 245 | paths: [artifacts/version.txt] |
| 246 | expire_in: 14d |
| 247 | |
| 248 | exp:build:linux: |
| 249 | extends: [.rust, .experimental] |
| 250 | stage: build |
| 251 | needs: [exp:version, test] |
| 252 | cache: |
| 253 | key: cargo-exp-linux |
| 254 | paths: [target/, cargo-home/] |
| 255 | script: |
| 256 | - bash scripts/ci/set-version.sh |
| 257 | - cargo build --release --locked |
| 258 | - bash scripts/ci/experimental-package-linux.sh |
| 259 | artifacts: |
| 260 | paths: [dist/posprint-experimental-linux-x86_64.tar.gz] |
| 261 | expire_in: 30d |
| 262 | |
| 263 | exp:build:windows: |
| 264 | extends: [.rust, .experimental] |
| 265 | stage: build |
| 266 | needs: [exp:version, test] |
| 267 | cache: |
| 268 | key: cargo-exp-windows |
| 269 | paths: [target/, cargo-home/] |
| 270 | before_script: |
| 271 | - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home" |
| 272 | - export PATH="$CARGO_HOME/bin:$PATH" |
| 273 | - apt-get update -qq |
| 274 | - apt-get install -y -qq gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 |
| 275 | - rustup target add x86_64-pc-windows-gnu |
| 276 | - ln -sf /usr/bin/x86_64-w64-mingw32-windres /usr/local/bin/windres |
| 277 | script: |
| 278 | - bash scripts/ci/set-version.sh |
| 279 | - cargo build --release --locked --target x86_64-pc-windows-gnu |
| 280 | - mkdir -p dist |
| 281 | - cp target/x86_64-pc-windows-gnu/release/posprint.exe dist/posprint-experimental-windows-x86_64.exe |
| 282 | artifacts: |
| 283 | paths: [dist/posprint-experimental-windows-x86_64.exe] |
| 284 | expire_in: 30d |
| 285 | |
| 286 | exp:release: |
| 287 | extends: .experimental |
| 288 | stage: release |
| 289 | image: bluegit/base |
| 290 | needs: [exp:version, exp:build:linux, exp:build:windows] |
| 291 | resource_group: experimental-release |
| 292 | script: |
| 293 | - bash scripts/ci/experimental-release.sh |