BlueGit

timfa posprint

Files

posprint / blue-ci-cd.yml

blue-ci-cd.yml

blue-ci-cd.yml 7.5 KiB Download Raw
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
19stages: [test, build, release, publish]
20
21variables:
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
28workflow:
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 - if: $CI_PIPELINE_SOURCE == "web"
35 - if: $CI_PIPELINE_SOURCE == "api"
36
37.master:
38 rules:
39 - if: $CI_PIPELINE_SOURCE == "merge_request_event"
40 when: never
41 - if: $CI_COMMIT_BRANCH == "master"
42
43.rust:
44 image: rust:1.96-bookworm
45 timeout: 2h
46 before_script:
47 - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home"
48 - export PATH="$CARGO_HOME/bin:$PATH"
49 - apt-get update -qq
50 - 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
51
52test:
53 extends: .rust
54 stage: test
55 cache:
56 key: cargo-test
57 paths: [target/, cargo-home/]
58 script:
59 - cargo test --verbose
60
61version:
62 rules:
63 - if: $CI_PIPELINE_SOURCE == "merge_request_event"
64 when: never
65 - if: $CI_COMMIT_BRANCH == "master"
66 - if: $CI_PIPELINE_SOURCE == "web"
67 - if: $CI_PIPELINE_SOURCE == "api"
68 stage: test
69 image: bluegit/base
70 needs: []
71 script:
72 - mkdir -p artifacts
73 - bash scripts/ci/next-version.sh | tee artifacts/version.txt
74 artifacts:
75 paths: [artifacts/version.txt]
76 expire_in: 14d
77
78build:linux-deb:
79 extends: [.rust, .master]
80 stage: build
81 needs: [version, test]
82 cache:
83 key: cargo-deb
84 paths: [target/, cargo-home/]
85 script:
86 - apt-get install -y -qq dpkg-dev
87 - cargo install cargo-deb --locked
88 - bash scripts/ci/set-version.sh
89 - cargo deb
90 - mkdir -p dist
91 - cp target/debian/posprint_$(cat artifacts/version.txt)-1_amd64.deb dist/amd64.deb
92 artifacts:
93 # BlueGit artifacts are exact file paths (no globs or directories).
94 paths: [dist/amd64.deb]
95 expire_in: 30d
96
97build:linux-arch:
98 extends: .master
99 stage: build
100 image: archlinux/archlinux:base-devel
101 timeout: 2h
102 needs: [version, test]
103 script:
104 # BlueGit sets no CI_PROJECT_DIR; jobs start in the checkout.
105 - export CI_PROJECT_DIR="$PWD"
106 - pacman -Syu --noconfirm
107 - pacman -S --noconfirm --needed rust pkgconf openssl libxkbcommon libxcb dbus wayland libx11 fontconfig freetype2 libglvnd git rsync
108 - bash scripts/ci/set-version.sh
109 - export PKGVER="$(cat artifacts/version.txt)"
110 - sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
111 - useradd -m builduser
112 - chown -R builduser:builduser "$CI_PROJECT_DIR"
113 - su builduser -c "cd $CI_PROJECT_DIR/packaging/arch && makepkg -f --noconfirm"
114 - mkdir -p "$CI_PROJECT_DIR/dist"
115 - |
116 set -euo pipefail
117 shopt -s nullglob
118 mains=("$CI_PROJECT_DIR"/packaging/arch/posprint-${PKGVER}-*-x86_64.pkg.tar.zst)
119 shopt -u nullglob
120 if [[ ${#mains[@]} -ne 1 ]]; then
121 echo "Expected one non-debug Arch package, found ${#mains[@]}" >&2
122 exit 1
123 fi
124 cp "${mains[0]}" "$CI_PROJECT_DIR/dist/x86_64.pkg.tar.zst"
125 out="$CI_PROJECT_DIR/dist/x86_64-bin.tar.gz"
126 bash "$CI_PROJECT_DIR/scripts/make-linux-bin-tarball.sh" "${mains[0]}" "$out" "$PKGVER"
127 test -s "$out"
128 artifacts:
129 paths: [dist/x86_64.pkg.tar.zst, dist/x86_64-bin.tar.gz]
130 expire_in: 30d
131
132# Cross-compiled with MinGW (no Windows runner on BlueGit).
133build:windows:
134 extends: [.rust, .master]
135 stage: build
136 needs: [version, test]
137 cache:
138 key: cargo-windows
139 paths: [target/, cargo-home/]
140 before_script:
141 - export CARGO_HOME="$CI_PROJECT_DIR/cargo-home"
142 - export PATH="$CARGO_HOME/bin:$PATH"
143 - apt-get update -qq
144 - apt-get install -y -qq gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64
145 - rustup target add x86_64-pc-windows-gnu
146 # winres calls plain `windres`; use the MinGW one.
147 - ln -sf /usr/bin/x86_64-w64-mingw32-windres /usr/local/bin/windres
148 script:
149 - bash scripts/ci/set-version.sh
150 - cargo build --release --locked --target x86_64-pc-windows-gnu
151 - mkdir -p dist
152 - cp target/x86_64-pc-windows-gnu/release/posprint.exe dist/
153 artifacts:
154 paths: [dist/posprint.exe]
155 expire_in: 30d
156
157# Cross-built on Linux (no macOS runner): universal Posprint.app as zip.
158# Untested on a real Mac in CI; not notarized.
159build:macos:
160 stage: build
161 image: ghcr.io/rust-cross/cargo-zigbuild:latest
162 timeout: 2h
163 needs: [version, test]
164 rules:
165 - if: $CI_PIPELINE_SOURCE == "merge_request_event"
166 when: never
167 - if: $CI_COMMIT_BRANCH == "master"
168 # Manual pipeline on a branch: build-check macOS only.
169 - if: $CI_PIPELINE_SOURCE == "web"
170 - if: $CI_PIPELINE_SOURCE == "api"
171 cache:
172 key: cargo-macos
173 paths: [target/, cargo-home/]
174 script:
175 - export CARGO_HOME="$PWD/cargo-home" PATH="$PWD/cargo-home/bin:$PATH"
176 - bash scripts/ci/set-version.sh
177 - bash scripts/ci/build-macos.sh
178 artifacts:
179 paths: [dist/macos-universal.zip]
180 expire_in: 30d
181
182# Safe AUR check on every master pipeline: real SSH key and AUR clone,
183# PKGBUILD/.SRCINFO generation, but AUR_DRY_RUN=1 never pushes.
184aur:dry-run:
185 extends: .master
186 stage: release
187 image: archlinux/archlinux:base-devel
188 needs: [version, build:linux-arch]
189 allow_failure: true
190 script:
191 - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux
192 - bash scripts/aur-ssh-setup.sh
193 - last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)"
194 - export POSPRINT_SOURCE_ARCHIVE_URL="$CI_API_URL/projects/$CI_PROJECT_PATH/repository/tags/$last/archive"
195 - cp dist/x86_64-bin.tar.gz "dist/posprint-$(cat artifacts/version.txt)-x86_64.tar.gz"
196 - AUR_DRY_RUN=1 bash scripts/publish-aur.sh "$(cat artifacts/version.txt)"
197
198release:
199 extends: .master
200 stage: release
201 image: bluegit/base
202 needs: [version, build:linux-deb, build:linux-arch, build:windows, build:macos]
203 resource_group: release
204 script:
205 - bash scripts/ci/release.sh
206 artifacts:
207 paths: [artifacts/released.txt]
208 expire_in: 30d
209
210publish:aur:
211 extends: .master
212 stage: publish
213 image: archlinux/archlinux:base-devel
214 needs: [version, release, build:linux-arch]
215 allow_failure: true
216 resource_group: aur
217 script:
218 - pacman -Syu --noconfirm --needed git openssh curl coreutils shadow util-linux
219 - bash scripts/aur-ssh-setup.sh
220 - if [ "$(cat artifacts/released.txt)" = "skip" ]; then echo "No new release in this pipeline; AUR unchanged."; exit 0; fi
221 - cp dist/x86_64-bin.tar.gz "dist/posprint-$(cat artifacts/version.txt)-x86_64.tar.gz"
222 - bash scripts/publish-aur.sh "$(cat artifacts/version.txt)"