| 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` is manual 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 with the build artifacts as assets. Then publish:aur |
| 9 | # updates the AUR packages posprint and posprint-bin. |
| 10 | # Tag pushes never run a pipeline (old tags must not rebuild). |
| 11 | # |
| 12 | # Secrets (repository, protected): AUR_SSH_PRIVATE_KEY_B64, |
| 13 | # AUR_GIT_AUTHOR_NAME, AUR_GIT_AUTHOR_EMAIL. |
| 14 | |
| 15 | stages: [test, build, release, publish] |
| 16 | |
| 17 | variables: |
| 18 | CARGO_TERM_COLOR: always |
| 19 | RUST_BACKTRACE: "1" |
| 20 | CARGO_BUILD_JOBS: "3" |
| 21 | CARGO_PROFILE_DEV_DEBUG: "false" |
| 22 | CARGO_PROFILE_TEST_DEBUG: "false" |
| 23 | |
| 24 | workflow: |
| 25 | rules: |
| 26 | - if: $CI_COMMIT_TAG != "" |
| 27 | when: never |
| 28 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 29 | - if: $CI_COMMIT_BRANCH == "master" |
| 30 | - if: $CI_PIPELINE_SOURCE == "web" |
| 31 | - if: $CI_PIPELINE_SOURCE == "api" |
| 32 | |
| 33 | .master: |
| 34 | rules: |
| 35 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 36 | when: never |
| 37 | - if: $CI_COMMIT_BRANCH == "master" |
| 38 | |
| 39 | .rust: |
| 40 | image: rust:1.96-bookworm |
| 41 | timeout: 2h |
| 42 | before_script: |
| 43 | - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home" |
| 44 | - export PATH="$CARGO_HOME/bin:$PATH" |
| 45 | - apt-get update -qq |
| 46 | - 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 |
| 47 | |
| 48 | test: |
| 49 | extends: .rust |
| 50 | stage: test |
| 51 | cache: |
| 52 | key: cargo-test |
| 53 | paths: [target/, cargo-home/] |
| 54 | script: |
| 55 | - cargo test --verbose |
| 56 | |
| 57 | version: |
| 58 | extends: .master |
| 59 | stage: test |
| 60 | image: bluegit/base |
| 61 | needs: [] |
| 62 | script: |
| 63 | - mkdir -p artifacts |
| 64 | - bash scripts/ci/next-version.sh | tee artifacts/version.txt |
| 65 | artifacts: |
| 66 | paths: [artifacts/version.txt] |
| 67 | expire_in: 14d |
| 68 | |
| 69 | build:linux-deb: |
| 70 | extends: [.rust, .master] |
| 71 | stage: build |
| 72 | needs: [version, test] |
| 73 | cache: |
| 74 | key: cargo-deb |
| 75 | paths: [target/, cargo-home/] |
| 76 | script: |
| 77 | - apt-get install -y -qq dpkg-dev |
| 78 | - cargo install cargo-deb --locked |
| 79 | - bash scripts/ci/set-version.sh |
| 80 | - cargo deb |
| 81 | - mkdir -p dist |
| 82 | - cp target/debian/*.deb dist/ |
| 83 | artifacts: |
| 84 | paths: [dist/] |
| 85 | expire_in: 30d |
| 86 | |
| 87 | build:linux-arch: |
| 88 | extends: .master |
| 89 | stage: build |
| 90 | image: archlinux/archlinux:base-devel |
| 91 | timeout: 2h |
| 92 | needs: [version, test] |
| 93 | script: |
| 94 | # BlueGit sets no CI_PROJECT_DIR; jobs start in the checkout. |
| 95 | - export CI_PROJECT_DIR="$PWD" |
| 96 | - pacman -Syu --noconfirm |
| 97 | - pacman -S --noconfirm --needed rust pkgconf openssl libxkbcommon libxcb dbus wayland libx11 fontconfig freetype2 libglvnd git rsync |
| 98 | - bash scripts/ci/set-version.sh |
| 99 | - export PKGVER="$(cat artifacts/version.txt)" |
| 100 | - sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD |
| 101 | - useradd -m builduser |
| 102 | - chown -R builduser:builduser "$CI_PROJECT_DIR" |
| 103 | - su builduser -c "cd $CI_PROJECT_DIR/packaging/arch && makepkg -f --noconfirm" |
| 104 | - mkdir -p "$CI_PROJECT_DIR/dist" |
| 105 | - | |
| 106 | set -euo pipefail |
| 107 | shopt -s nullglob |
| 108 | mains=("$CI_PROJECT_DIR"/packaging/arch/posprint-${PKGVER}-*-x86_64.pkg.tar.zst) |
| 109 | shopt -u nullglob |
| 110 | if [[ ${#mains[@]} -ne 1 ]]; then |
| 111 | echo "Expected one non-debug Arch package, found ${#mains[@]}" >&2 |
| 112 | exit 1 |
| 113 | fi |
| 114 | cp "${mains[0]}" "$CI_PROJECT_DIR/dist/" |
| 115 | out="$CI_PROJECT_DIR/dist/posprint-${PKGVER}-x86_64.tar.gz" |
| 116 | bash "$CI_PROJECT_DIR/scripts/make-linux-bin-tarball.sh" "${mains[0]}" "$out" "$PKGVER" |
| 117 | test -s "$out" |
| 118 | artifacts: |
| 119 | paths: [dist/] |
| 120 | expire_in: 30d |
| 121 | |
| 122 | # Cross-compiled with MinGW (no Windows runner on BlueGit). |
| 123 | build:windows: |
| 124 | extends: [.rust, .master] |
| 125 | stage: build |
| 126 | needs: [version, test] |
| 127 | cache: |
| 128 | key: cargo-windows |
| 129 | paths: [target/, cargo-home/] |
| 130 | before_script: |
| 131 | - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home" |
| 132 | - export PATH="$CARGO_HOME/bin:$PATH" |
| 133 | - apt-get update -qq |
| 134 | - apt-get install -y -qq gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 |
| 135 | - rustup target add x86_64-pc-windows-gnu |
| 136 | # winres calls plain `windres`; use the MinGW one. |
| 137 | - ln -sf /usr/bin/x86_64-w64-mingw32-windres /usr/local/bin/windres |
| 138 | script: |
| 139 | - bash scripts/ci/set-version.sh |
| 140 | - cargo build --release --locked --target x86_64-pc-windows-gnu |
| 141 | - mkdir -p dist |
| 142 | - cp target/x86_64-pc-windows-gnu/release/posprint.exe dist/ |
| 143 | artifacts: |
| 144 | paths: [dist/posprint.exe] |
| 145 | expire_in: 30d |
| 146 | |
| 147 | # Safe AUR check on every master pipeline: real SSH key and AUR clone, |
| 148 | # PKGBUILD/.SRCINFO generation, but AUR_DRY_RUN=1 never pushes. |
| 149 | aur:dry-run: |
| 150 | extends: .master |
| 151 | stage: release |
| 152 | image: archlinux/archlinux:base-devel |
| 153 | needs: [version, build:linux-arch] |
| 154 | allow_failure: true |
| 155 | script: |
| 156 | - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux |
| 157 | - bash scripts/aur-ssh-setup.sh |
| 158 | - last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)" |
| 159 | - export POSPRINT_SOURCE_ARCHIVE_URL="$CI_API_URL/projects/$CI_PROJECT_PATH/repository/tags/$last/archive" |
| 160 | - AUR_DRY_RUN=1 bash scripts/publish-aur.sh "$(cat artifacts/version.txt)" |
| 161 | |
| 162 | release: |
| 163 | extends: .master |
| 164 | stage: release |
| 165 | image: bluegit/base |
| 166 | needs: [version, build:linux-deb, build:linux-arch, build:windows] |
| 167 | when: manual |
| 168 | resource_group: release |
| 169 | script: |
| 170 | - bash scripts/ci/release.sh |
| 171 | |
| 172 | publish:aur: |
| 173 | extends: .master |
| 174 | stage: publish |
| 175 | image: archlinux/archlinux:base-devel |
| 176 | needs: [version, release, build:linux-arch] |
| 177 | allow_failure: true |
| 178 | resource_group: aur |
| 179 | script: |
| 180 | - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux |
| 181 | - bash scripts/aur-ssh-setup.sh |
| 182 | - bash scripts/publish-aur.sh "$(cat artifacts/version.txt)" |