-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
456 lines (413 loc) · 13.2 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
stages:
- setup
- check
- build-check
- release-build
- package
- deploy
# prevent duplicate pipelines for merge request
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
variables:
RUST_MIN_VERSION: "1.77-buster"
RUST_REL_VERSION: "1.79-buster"
LINUX_RUSTIMG: "docker.io/library/rust:${RUST_VERSION}"
PKG_ROOT: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic"
.build-template:
stage: build-check
script:
- cargo build ${FEATURES} ${CARGO_FLAGS}
# make sure build introduces no diffs
# FIXME cannot be set there yet since we need a patch for FreeBSD
#- git diff --exit-code
.debian-build-template:
extends:
- .build-template
image: ${LINUX_RUSTIMG}
before_script:
- apt-get update
- apt-get install -y llvm-dev clang libxen-dev
# FIXME does not allow to pin a toolchain version
.cross-build-template:
extends:
- .build-template
image: ghcr.io/cross-rs/$CARGO_BUILD_TARGET:main
before_script:
# install Rust
- curl --silent --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
- . "$HOME/.cargo/env"
- rustup target add $CARGO_BUILD_TARGET
.cross-freebsd13-x86_64-build-template:
extends:
- .cross-build-template
variables:
CARGO_BUILD_TARGET: "x86_64-unknown-freebsd"
CROSS_SYSROOT: "/usr/local/x86_64-unknown-freebsd13"
before_script:
- !reference [.cross-build-template,before_script]
# cross sysroot does not match its toolchain
- mkdir -p $CROSS_SYSROOT/usr
- ln -s ../include $CROSS_SYSROOT/usr/include
- ln -s ../lib $CROSS_SYSROOT/usr/lib
# link will not look for the proper libs otherwise
- export RUSTFLAGS="-L$CROSS_SYSROOT/usr/lib"
# build dependencies
- export FREEBSD_MIRROR=$(/freebsd-fetch-best-mirror.sh)
- /freebsd-setup-packagesite.sh
- /freebsd-install-package.sh xen-tools
.cross-windows-build-template:
extends:
- .cross-build-template
variables:
CARGO_BUILD_TARGET: "x86_64-pc-windows-gnu"
.cross-linux-aarch64-build-template:
extends:
- .cross-build-template
variables:
CARGO_BUILD_TARGET: "aarch64-unknown-linux-gnu"
BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu: "--sysroot=/usr/aarch64-linux-gnu -idirafter/usr/include"
.only-scheduled:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
.not-scheduled:
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
## quick checks
clippy:
stage: check
extends:
- .debian-build-template
variables:
RUST_VERSION: "latest"
before_script:
- !reference [.debian-build-template,before_script]
- rustup component add clippy
script:
- cargo clippy
cargo-lock:
stage: check
extends:
- .debian-build-template
variables:
RUST_VERSION: "${RUST_REL_VERSION}"
script:
- cargo tree
# if Cargo.lock was not commited, this will show here
- git diff --exit-code
## common defs
.featurematrix:
parallel:
matrix:
- FEATURES:
- ""
- "--no-default-features"
- "--no-default-features -F xenstore"
- "--no-default-features -F net_netlink"
- "--no-default-features -F net_pnet"
#
- "--no-default-features -F xenstore,static"
- "-F static"
.featurematrix.no-netlink:
parallel:
matrix:
- FEATURES:
- "--no-default-features"
- "--no-default-features -F xenstore"
- "--no-default-features -F net_pnet"
- "--no-default-features -F xenstore,net_pnet"
## this matrix is only by FreeBSD today, and we cannot link
## statically on FreeBSD because libxenstore is not built as PIE
#- "--no-default-features -F xenstore,static"
#- "--no-default-features -F xenstore,static,net_pnet"
## standard jobs building with shipped Cargo.lock
env-setup:
stage: setup
image: docker.io/library/alpine:latest
before_script:
- |
if [ "$CI_COMMIT_REF_NAME" = "main" ]; then
apk add git
fi
script:
- |
case "$CI_COMMIT_REF_NAME" in
main) UPSTREAMVERSION=$(git describe)
TILDEVERSION=$UPSTREAMVERSION
RPMVERSION=$(echo $UPSTREAMVERSION | tr "-" "+")
;;
*) UPSTREAMVERSION=$(awk -F'"' < Cargo.toml '/^\[/ { pkg=0 }; /^\[package\]$/ { pkg=1 }; /^version = "(.*)"/ { if (pkg) print $2 }')
# both DEB and RPM use "~" to sort pre-releases before releases
TILDEVERSION=$(echo $UPSTREAMVERSION | tr "-" "~")
RPMVERSION=$TILDEVERSION
;;
esac
# update channel must be the same for matching packaging and deploy
# jobs, set it once globally
- |
case "${CI_COMMIT_TAG}" in
"") UPDATE_CHANNEL="${CI_COMMIT_REF_NAME}" ;;
*-*) UPDATE_CHANNEL="testing" ;;
*) UPDATE_CHANNEL="release" ;;
esac
- echo "UPDATE_CHANNEL=${UPDATE_CHANNEL}" > version.env
- echo "UPSTREAMVERSION=${UPSTREAMVERSION}" >> version.env
- echo "TILDEVERSION=${TILDEVERSION}" >> version.env
- echo "RPMVERSION=${RPMVERSION}" >> version.env
- cat version.env
artifacts:
reports:
# propagates variables into the pipeline level
dotenv: version.env
build-linux-everycommit:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
parallel: !reference [.featurematrix,parallel]
extends:
- .debian-build-template
variables:
CARGO_FLAGS: "-v"
RUST_VERSION: "${RUST_MIN_VERSION}"
before_script:
- printf "\e[0Ksection_start:$(date +%s):before_script[collapsed=true]\r\e[0K\e[1;33mBuild setup\e[1;0m\n"
- !reference [.debian-build-template,before_script]
- printf "\e[0Ksection_end:$(date +%s):before_script\r\e[0K\n"
script:
# let git-rebase run the build for each commit, but not fail with
# commit subject starts with "WIP" (gitlab also uses this string
# to switch a PR back to draft, mitigating the risk to push a
# failing commit)
- git rebase --rebase-merges $CI_MERGE_REQUEST_DIFF_BASE_SHA
--exec 'devscripts/gitlab-ci-runbuild.sh cargo build ${FEATURES} ${CARGO_FLAGS} && git status'
after_script:
# since Git Strategy is "fetch", avoid poluting subsequent runs
# (but as of v16.9 it still won't be run on timeout or cancel)
- git rebase --abort || true
build-linux:
parallel: !reference [.featurematrix,parallel]
extends:
- .debian-build-template
variables:
CARGO_FLAGS: "-v"
RUST_VERSION: "${RUST_MIN_VERSION}"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# building branch tip already included in 'everycommit'
when: never
- !reference [.not-scheduled,rules]
build-release-linux-x86_64:
stage: release-build
extends:
- .debian-build-template
- .not-scheduled
variables:
FEATURES: "-F static"
CARGO_FLAGS: "--release"
RUST_VERSION: "${RUST_REL_VERSION}"
artifacts:
paths:
- target/release/xen-guest-agent
build-freebsd13-x86_64:
parallel: !reference [.featurematrix.no-netlink,parallel]
extends:
- .cross-freebsd13-x86_64-build-template
- .not-scheduled
variables:
CARGO_FLAGS: "-v"
build-freebsd13-netlink-x86_64:
variables:
FEATURES: ""
extends:
- .cross-freebsd13-x86_64-build-template
- .not-scheduled
variables:
CARGO_FLAGS: "-v"
before_script:
- !reference [.cross-freebsd13-x86_64-build-template,before_script]
- mkdir .cargo
- cp devscripts/cargo-freebsd-netlink.toml .cargo/config.toml
- cargo update -p libc -p rtnetlink
after_script:
# since Git Strategy is "fetch", avoid poluting subsequent runs
# (but as of v16.9 it still won't be run on timeout or cancel)
- git checkout HEAD Cargo.toml
artifacts:
paths:
- target/x86_64-unknown-freebsd/debug/xen-guest-agent
build-release-freebsd13-x86_64:
stage: release-build
extends:
- .cross-freebsd13-x86_64-build-template
- .not-scheduled
variables:
FEATURES: "--no-default-features -F xenstore,net_pnet"
CARGO_FLAGS: "--release"
artifacts:
paths:
- target/x86_64-unknown-freebsd/release/xen-guest-agent
build-windows-x86_64:
extends:
- .cross-windows-build-template
- .not-scheduled
variables:
CARGO_FLAGS: "-v"
FEATURES: "--no-default-features"
artifacts:
paths:
- target/x86_64-pc-windows-gnu/debug/xen-guest-agent.exe
build-linux-aarch64:
parallel: !reference [.featurematrix,parallel]
extends:
- .cross-linux-aarch64-build-template
- .not-scheduled
variables:
CARGO_FLAGS: "-v"
before_script:
- !reference [.cross-build-template,before_script]
- dpkg --add-architecture arm64
- apt-get update
- apt-get install -y libxen-dev:arm64
## continuous checking against most recent dependencies (also on push/PR)
build-latest-linux:
parallel: !reference [.featurematrix,parallel]
extends:
- .debian-build-template
variables:
CARGO_FLAGS: "-v"
RUST_VERSION: "${RUST_MIN_VERSION}"
before_script:
- !reference [".debian-build-template", "before_script"]
- mv Cargo.lock Cargo.lock.current
after_script:
# show which dependencies changed in Cargo.lock
- git diff
# since Git Strategy is "fetch", avoid poluting subsequent runs
# (but as of v16.9 it still won't be run on timeout or cancel)
- git checkout HEAD Cargo.toml
build-latest-freebsd13-x86_64:
parallel: !reference [.featurematrix.no-netlink,parallel]
extends:
- .cross-freebsd13-x86_64-build-template
variables:
CARGO_FLAGS: "-v"
before_script:
- !reference [".cross-freebsd13-x86_64-build-template", "before_script"]
- mv Cargo.lock Cargo.lock.current
after_script:
# show which dependencies changed in Cargo.lock
- git diff
# since Git Strategy is "fetch", avoid poluting subsequent runs
# (but as of v16.9 it still won't be run on timeout or cancel)
- git checkout HEAD Cargo.toml
## source packaging
pkg-source:
stage: package
image: ${LINUX_RUSTIMG}
variables:
RUST_VERSION: "latest"
extends:
- .not-scheduled
needs:
- env-setup
script:
- cargo package --no-verify
- CRATEFILE=$(basename target/package/xen-guest-agent-*.crate)
- mv target/package/${CRATEFILE} target/package/${CRATEFILE%.crate}.tar.gz
artifacts:
paths:
- target/package/*.tar.gz
## packaging from binary artifacts
pkg-deb-amd64:
stage: package
image: docker.io/library/debian:10
extends:
- .not-scheduled
needs:
- env-setup
- build-release-linux-x86_64
before_script:
- apt update
- apt install -y build-essential debhelper apt-utils
- dpkg-checkbuilddeps
script:
- >-
sed < debian/changelog.in > debian/changelog
-e "s/@@VERSION@@/$TILDEVERSION/"
-e "s/@@AUTHOR@@/$GITLAB_USER_NAME <$GITLAB_USER_EMAIL>/"
-e "s/@@DATE@@/$(date --rfc-822)/"
- fakeroot debian/rules binary AGENT_BINARY="target/release/xen-guest-agent"
- mv -v ../*.deb target/release/
# repository metadata
- cd target/release
# mangle names to avoid chars rejected by the gitlab package registry,
# see https://gitlab.com/gitlab-org/gitlab/-/issues/413517
- |
if [ "${UPSTREAMVERSION}" != "${TILDEVERSION}" ]; then
for FILE in *.deb; do
mv $FILE $(echo $FILE | tr "~" "-")
done
fi
- apt-ftparchive generate ../../apt-ftparchive.conf
# post-processing so we can use `deb https://...generic/deb-amd64/ main/`
- 'sed -i "s,^Filename: ./,Filename: ${UPDATE_CHANNEL}/," Packages'
- apt-ftparchive release .
-o APT::FTPArchive::Release::Description="xen-guest-agent CI packages for ${UPDATE_CHANNEL}"
-o APT::FTPArchive::Release::Label="xen-guest-agent-ci"
-o APT::FTPArchive::Release::Suite="${UPDATE_CHANNEL}"
> Release.part
- mv Release.part Release
artifacts:
paths:
- target/release/*.deb
- target/release/*Release*
- target/release/Packages*
- target/release/Contents-*
# The artifact repo does not seem to work well as an APT source, APT
# gets HTP 400 on Packages for some reason, so deploy it to a package
# repository instead.
deploy-deb-amd64:
stage: deploy
extends:
- .not-scheduled
needs:
- env-setup
- pkg-deb-amd64
image: docker.io/curlimages/curl:latest
script:
- cd target/release
- for FILE in *; do
- echo "uploading '$FILE'"
- >
curl --silent --header "JOB-TOKEN: $CI_JOB_TOKEN"
--upload-file "$FILE"
"${PKG_ROOT}/deb-amd64/${UPDATE_CHANNEL}/${FILE}"
- done
pkg-rpm-x86_64:
stage: package
image: registry.fedoraproject.org/fedora:37
extends:
- .not-scheduled
needs:
- env-setup
- build-release-linux-x86_64
before_script:
- dnf install -y rpm-build dnf-utils
- mkdir SOURCES
- ln -sr target/release/xen-guest-agent SOURCES/
- ln -sr startup/xen-guest-agent.service SOURCES/
- >-
sed < xen-guest-agent.spec.in > xen-guest-agent.spec
-e "s/@@UPSTREAMVERSION@@/$UPSTREAMVERSION/"
-e "s/@@VERSION@@/$RPMVERSION/"
-e "s/@@AUTHOR@@/$GITLAB_USER_NAME <$GITLAB_USER_EMAIL>/"
-e "s/@@DATE@@/$(date +'%a %b %d %Y')/"
- dnf builddep xen-guest-agent.spec -y
script:
- 'rpmbuild -bb xen-guest-agent.spec --define "_topdir $(pwd)"'
artifacts:
paths:
- RPMS/*/*.rpm