-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrust.gitlab-ci.yml
358 lines (336 loc) · 10.3 KB
/
rust.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
stages:
- check
- build
- test
- docker
- test-2
- release
- deploy
workflow:
rules:
- if: $CI_PIPELINE_SOURCE != 'push' || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
when: always
- when: never
.docker-default:
image: docker:20.10.6
services:
- name: docker:20.10.6-dind
entrypoint: [ "env", "-u", "DOCKER_HOST" ]
command: [ "dockerd-entrypoint.sh" ]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.rust-default:
image: registry.gitlab.com/tobip64/rust-gitlab-ci:latest
cache:
- key: $CI_COMMIT_REF
paths: [ target/ ]
- key: cargo
paths: [ cargo/ ]
interruptible: true
timeout: 30m
variables:
CARGO_HOME: $CI_PROJECT_DIR/cargo
CACHE_FALLBACK_KEY: $CI_DEFAULT_BRANCH
parallel:
matrix:
- CHANNEL: [ stable, beta, nightly ]
rules:
- if: $CHANNEL == "stable"
allow_failure: false
- allow_failure: true
before_script:
- rustup --version && rustc --version && cargo --version && echo $RUSTFLAGS && echo $CARGO_OPTS
check:clippy:
extends: .rust-default
stage: check
script:
- 'cargo +$CHANNEL clippy
--color always
--verbose
--all-targets
--all-features
--message-format=json
$CARGO_OPTS
| gitlab-report -p clippy > gl-code-quality-report.json'
artifacts:
when: always
reports:
codequality: gl-code-quality-report.json
check:fmt:
extends: .rust-default
stage: check
parallel:
rules:
- if: $RUN_RUST_FMT
script:
- cargo +stable fmt $CARGO_OPTS -- --check
allow_failure: true
check:audit:
extends: .rust-default
stage: check
parallel:
script:
- cargo audit --color=always --json $CARGO_OPTS | gitlab-report -p audit -f gl-sast > gl-sast-report.json
artifacts:
when: always
reports:
sast: gl-sast-report.json
check:geiger:
extends: .rust-default
stage: check
parallel:
script:
- cargo geiger --all-dependencies --color always --output-format Json $CARGO_OPTS | gitlab-report -p geiger -f gl-sast > gl-sast-report.json
artifacts:
when: always
reports:
sast: gl-sast-report.json
build:
extends: .rust-default
stage: build
needs: [ "check:clippy" ]
timeout: 1h
parallel:
matrix:
- CHANNEL: [ stable, beta, nightly ]
PROFILE: [ debug, release ]
TARGET:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
- mips64el-unknown-linux-muslabi64
- wasm32-wasi
CARGO_OPTS: [ "--workspace --all-targets --all-features" ]
script:
- cargo +$CHANNEL build --verbose --color always --target $TARGET $([[ $PROFILE == "release" ]] && echo "--release" || echo "") $CARGO_OPTS
artifacts:
paths:
- target/$TARGET/$PROFILE/*
- Dockerfile
# requires nightly
.build:multiarch:
extends: .rust-default
stage: build
needs: [ "check:clippy" ]
timeout: 1h
parallel:
matrix:
- CHANNEL: [ nightly ]
PROFILE: [ debug, release ]
CARGO_OPTS: [ "--workspace --all-targets --all-features" ]
script:
- '[[ $PROFILE == "debug" ]] && export RUSTFLAGS="$RUSTFLAGS -Zinstrument-coverage" || true'
- 'cargo +$CHANNEL build
$([[ $PROFILE == "release" ]] && echo "--release" || echo "")
--verbose
--color=always
--target x86_64-unknown-linux-musl
--target powerpc64le-unknown-linux-musl
--target aarch64-unknown-linux-musl
--target riscv64gc-unknown-linux-musl
--target wasm32-wasi
-Z multitarget
-Z build-std
$CARGO_OPTS'
artifacts:
paths:
- target/*/$PROFILE/*
- Dockerfile
build:docs:
extends: .rust-default
stage: build
needs: [ "check:clippy" ]
parallel:
script:
- cargo +stable doc --color=always --verbose --no-deps $CARGO_OPTS
artifacts:
paths:
- target/doc
test:test:
extends: .rust-default
stage: test
needs: [ build ]
script:
- 'LLVM_PROFILE_FILE="$CI_PROJECT_NAME-%p-%m.profraw" cargo +$CHANNEL test
--verbose
--color always
--workspace
--all-targets
--all-features
--no-fail-fast
--
-Z unstable-options
--format json
$CARGO_OPTS
| gitlab-report -p test > results.xml'
after_script:
- 'grcov .
--binary-path ./target/x86_64-unknown-linux-musl/debug/
--source-dir .
--output-type cobertura
--output-path coverage.xml
--branch
--ignore-not-existing
--ignore "/*"'
- mkdir results/
- cp results.xml results/results.xml
- allure generate -c results/
artifacts:
when: always
paths:
- allure-report/
reports:
junit: results.xml
# cobertura: coverage.xml
test:bench:
extends: .rust-default
stage: test
needs: [ build ]
script:
- 'cargo +$CHANNEL bench
--verbose
--color always
--workspace
--all-targets
--all-features
$CARGO_OPTS
--
-Z unstable-options
--format json
| gitlab-report -p bench > metrics.txt'
artifacts:
when: always
reports:
metrics: metrics.txt
release:registry:
stage: release
image: registry.gitlab.com/tobip64/rust-gitlab-ci:latest
needs: [ "check:audit", "build", "test:test" ]
timeout: 5m
variables:
GIT_STRATEGY: none
script:
- 'cd target
&& find . -mindepth 3 -maxdepth 3 -type f
| tar -czv -T -
| curl --fail --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file . $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/$CI_COMMIT_REF_SLUG/$CI_COMMIT_SHA/package.tar.gz'
.release:docker:
image: docker:20.10.6
stage: release
needs: [ "check:audit", "build", "test:test" ]
services:
- name: docker:20.10.6-dind
entrypoint: [ "env", "-u", "DOCKER_HOST" ]
command: [ "dockerd-entrypoint.sh" ]
variables:
GIT_STRATEGY: none
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_PLATFORM: "linux/amd64,linux/arm64/v8"
parallel:
matrix:
- CHANNEL: [ stable, beta, nightly ]
PROFILE: [ debug, release ]
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker buildx create --name builder
- docker buildx use builder
- 'docker buildx build
-f Dockerfile
--platform $DOCKER_PLATFORM
--build-arg CHANNEL=$CHANNEL
--build-arg PROFILE=$PROFILE
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA-$CHANNEL-$PROFILE
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CHANNEL-$PROFILE-latest
.'
- docker push --all-tags $CI_REGISTRY_IMAGE
release:pages:
stage: release
image: alpine:latest
needs: [ "check:audit", "build:docs", "test:test" ]
variables:
GIT_STRATEGY: none
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
- if: $CI_COMMIT_MESSAGE =~ /\/release/
script:
- mv target/doc public/
- echo '<meta http-equiv="refresh" content="0; url={{ LIBRARY NAME }}">' > public/index.html
artifacts:
paths:
- public/
.release:gitlab:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs: [ "check:audit", "test:test" ]
variables:
GIT_STRATEGY: none
rules:
- if: $CI_COMMIT_TAG
when: manual
- if: $CI_COMMIT_MESSAGE =~ /\/release/
script:
- release-cli create
--name $CI_COMMIT_TAG
--description $CI_COMMIT_MESSAGE
--tag-name $CI_COMMIT_TAG
--ref $CI_COMMIT_SHA
--assets-link '{"name":"Package","url":"${CI_REPOSITORY_URL}/packages/generic/${CI_COMMIT_REF_SLUG}/${CI_COMMIT_SHA}","link_type":"package"}'
--assets-link '{"name":"Docker Image","url":"$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA-stable-release","link_type":"image"}'
--assets-link '{"name":"Docs","url":"$CI_PAGES_URL"}'
release:
name: $CI_COMMIT_TAG
description: './CHANGELOG.md'
tag_name: $CI_COMMIT_TAG
ref: $CI_COMMIT_SHA
.release:crates:
image: registry.gitlab.com/tobip64/rust-gitlab-ci:latest
stage: release
needs: [ "check:audit", "build", "test:test" ]
rules:
- if: $CI_COMMIT_TAG
when: manual
- if: $CI_COMMIT_MESSAGE =~ /\/release/
before_script:
- rustup --version && rustc --version && cargo --version && echo $RUSTFLAGS
script:
- cargo publish --token $CARGO_REGISTRY_TOKEN $CARGO_OPTS
.deploy:
stage: deploy
needs: [build, "release:registry"]
image: registry.gitlab.com/tobip64/rust-gitlab-ci:latest
retry: 2
timeout: 5m
variables:
GIT_STRATEGY: none
.deploy:development:
extends: .deploy
environment:
name: development
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
.deploy:production:
extends: .deploy
environment:
name: production
rules:
- if: $CI_COMMIT_TAG
.deploy:review:
extends: .deploy
environment:
name: review/$CI_COMMIT_REF_NAME
on_stop: cleanup:review
rules:
- if: $CI_MERGE_REQUEST_ID
.cleanup:review:
extends: .deploy
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
rules:
- if: $CI_MERGE_REQUEST_ID