forked from use-ink/ink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
486 lines (445 loc) · 19.3 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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# .gitlab-ci.yml
#
# ink
#
# pipelines can be triggered manually in the web
default:
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
stages:
- lint
- check
- workspace
- examples
- ink-waterfall
- fuzz
- publish
variables:
GIT_STRATEGY: fetch
GIT_DEPTH: 100
CARGO_INCREMENTAL: 0
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
# CI_IMAGE is changed to "-:staging" when the CI image gets rebuilt
# read more https://github.com/paritytech/scripts/pull/244
CI_IMAGE: "paritytech/ink-ci-linux:production"
PURELY_STD_CRATES: "lang/codegen metadata engine"
ALSO_WASM_CRATES: "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
DELEGATOR_SUBCONTRACTS: "accumulator adder subber"
UPGRADEABLE_CONTRACTS: "forward-calls delegate-calls"
workflow:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH
.collect-artifacts: &collect-artifacts
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 7 days
paths:
- artifacts/
.rust-info-script: &rust-info-script
- rustup show
- cargo --version
- rustup +nightly show
- cargo +nightly --version
- cargo spellcheck --version
- bash --version
- sccache -s
.test-refs: &test-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME == "tags"
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
.docker-env: &docker-env
image: "${CI_IMAGE}"
before_script:
- *rust-info-script
- ./scripts/ci/pre_cache.sh
- sccache -s
interruptible: true
tags:
- linux-docker
.kubernetes-env: &kubernetes-env
interruptible: true
tags:
- kubernetes-parity-build
#### stage: lint
#
# Note: For all of these lints we `allow_failure` so that the rest of the build can
# continue running despite them not passing. Merging is still disallowed since (most) of
# the lint steps are marked as "Required" in GitHub.
spellcheck:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- cargo spellcheck check -v --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 -- recursive .
- cargo spellcheck check -v --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 -- recursive ./examples/*
allow_failure: true
fmt:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- cargo fmt --verbose --all -- --check
# For the UI tests we need to disable the license check
- cargo fmt --verbose --all -- --check ./crates/lang/tests/ui/contract/{pass,fail}/*.rs
- cargo fmt --verbose --all -- --check ./crates/lang/tests/ui/trait_def/{pass,fail}/*.rs
allow_failure: true
examples-fmt:
stage: lint
<<: *docker-env
<<: *test-refs
script:
# Note that we disable the license header check for the examples, since they are unlicensed.
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
cargo fmt --verbose --manifest-path ./examples/delegator/${contract}/Cargo.toml -- --check;
done
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo fmt --verbose --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml -- --check;
done
- cargo fmt --verbose --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml -- --check
allow_failure: true
clippy-std:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- for crate in ${ALL_CRATES}; do
cargo clippy --verbose --all-targets --all-features --manifest-path ./crates/${crate}/Cargo.toml -- -D warnings;
done
clippy-wasm:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- for crate in ${ALSO_WASM_CRATES}; do
cargo clippy --verbose --no-default-features --manifest-path ./crates/${crate}/Cargo.toml --target wasm32-unknown-unknown -- -D warnings;
done
allow_failure: true
examples-clippy-std:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
cargo clippy --verbose --all-targets --manifest-path ${example}/Cargo.toml -- -D warnings;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
cargo clippy --verbose --all-targets --manifest-path ./examples/delegator/${contract}/Cargo.toml -- -D warnings;
done
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo clippy --verbose --all-targets --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml -- -D warnings;
done
- cargo clippy --verbose --all-targets --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml -- -D warnings;
allow_failure: true
examples-clippy-wasm:
stage: lint
<<: *docker-env
<<: *test-refs
script:
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
cargo clippy --verbose --manifest-path ./examples/delegator/${contract}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
done
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo clippy --verbose --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
done
- cargo clippy --verbose --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
allow_failure: true
#### stage: check
check-std:
stage: check
<<: *docker-env
<<: *test-refs
script:
- for crate in ${ALL_CRATES}; do
cargo check --verbose --all-features --manifest-path ./crates/${crate}/Cargo.toml;
done
check-wasm:
stage: check
<<: *docker-env
<<: *test-refs
script:
- for crate in ${ALSO_WASM_CRATES}; do
cargo check --verbose --no-default-features --target wasm32-unknown-unknown --manifest-path ./crates/${crate}/Cargo.toml;
done
#### stage: workspace
build-std:
stage: workspace
<<: *docker-env
<<: *test-refs
needs:
- job: check-std
artifacts: false
script:
- for crate in ${ALL_CRATES}; do
cargo build --verbose --all-features --release --manifest-path ./crates/${crate}/Cargo.toml;
done
build-wasm:
stage: workspace
<<: *docker-env
<<: *test-refs
needs:
- job: check-wasm
artifacts: false
script:
- for crate in ${ALSO_WASM_CRATES}; do
cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path ./crates/${crate}/Cargo.toml;
done
test:
stage: workspace
<<: *docker-env
<<: *test-refs
needs:
- job: check-std
artifacts: false
variables:
# Since we run the tests with `--all-features` this implies the feature
# `ink-fuzz-tests` as well -- i.e. the fuzz tests are run.
# There's no way to disable a single feature while enabling all features
# at the same time, hence we use this workaround.
QUICKCHECK_TESTS: 0
script:
- cargo test --verbose --all-features --no-fail-fast --workspace
- cargo test --verbose --all-features --no-fail-fast --workspace --doc
docs:
stage: workspace
<<: *docker-env
<<: *test-refs
variables:
RUSTDOCFLAGS: -Dwarnings
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}-doc"
when: on_success
expire_in: 7 days
paths:
- ./crate-docs/
script:
- cargo doc --no-deps --all-features
-p scale-info -p ink_metadata
-p ink_env -p ink_storage -p ink_storage_derive
-p ink_primitives -p ink_prelude
-p ink_lang -p ink_lang_macro -p ink_lang_ir -p ink_lang_codegen
- mv ${CARGO_TARGET_DIR}/doc ./crate-docs
# FIXME: remove me after CI image gets nonroot
- chown -R nonroot:nonroot ./crate-docs
codecov:
stage: workspace
<<: *docker-env
<<: *test-refs
needs:
- job: check-std
artifacts: false
variables:
# For codecov it's sufficient to run the fuzz tests only once.
QUICKCHECK_TESTS: 1
INK_COVERAGE_REPORTING: "true"
CARGO_INCREMENTAL: 0
# Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
RUSTFLAGS: "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1
-Clink-dead-code -Copt-level=0 -Coverflow-checks=off"
# The `cargo-taurpalin` coverage reporting tool seems to have better code instrumentation and thus
# produces better results for Rust codebases in general. However, unlike `grcov` it requires
# running docker with `--security-opt seccomp=unconfined` which is why we use `grcov` instead.
before_script:
- *rust-info-script
# RUSTFLAGS are the cause target cache can't be used here
# FIXME: cust-covfix doesn't support the external target dir
# https://github.com/Kogia-sima/rust-covfix/issues/7
- unset "CARGO_TARGET_DIR"
- cargo clean
# make sure there's no stale coverage artifacts
- find . -name "*.profraw" -type f -delete
- find . -name "*.gcda" -type f -delete
script:
# RUSTFLAGS are the cause target cache can't be used here
- cargo build --verbose --all-features --workspace
- cargo test --verbose --all-features --no-fail-fast --workspace
# coverage with branches
- grcov . --binary-path ./target/debug/ --source-dir . --output-type lcov --llvm --branch
--ignore-not-existing --ignore "/*" --ignore "tests/*" --output-path lcov-w-branch.info
- rust-covfix lcov-w-branch.info --output lcov-w-branch-fixed.info
- codecov --token "$CODECOV_P_TOKEN" --file lcov-w-branch-fixed.info --nonZero
# lines coverage
- grcov . --binary-path ./target/debug/ --source-dir . --output-type lcov --llvm
--ignore-not-existing --ignore "/*" --ignore "tests/*" --output-path lcov-lines.info
- rust-covfix lcov-lines.info --output lcov-lines-fixed.info
- codecov --token "$CODECOV_TOKEN" --file lcov-lines-fixed.info --nonZero
#### stage: examples
examples-test:
stage: examples
<<: *docker-env
<<: *test-refs
needs:
- job: clippy-std
artifacts: false
script:
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
cargo test --verbose --manifest-path ${example}/Cargo.toml;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
cargo test --verbose --manifest-path ./examples/delegator/${contract}/Cargo.toml;
done
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo test --verbose --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml;
done
- cargo test --verbose --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml;
examples-contract-build:
stage: examples
<<: *docker-env
<<: *test-refs
script:
- cargo contract -V
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
pushd $example &&
cargo contract build &&
popd;
done
- pushd ./examples/delegator/ && ./build-all.sh && popd
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo contract build --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml;
done
- cargo contract build --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml
examples-docs:
stage: examples
<<: *docker-env
<<: *test-refs
variables:
RUSTDOCFLAGS: -Dwarnings
script:
# `--document-private-items` needs to be in here because currently our contract macro
# puts the contract functions in a private module.
# Once https://github.com/paritytech/ink/issues/336 has been implemented we can get rid
# of this flag.
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
cargo doc --manifest-path ${example}/Cargo.toml --document-private-items --verbose --no-deps;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
cargo doc --manifest-path ./examples/delegator/${contract}/Cargo.toml --document-private-items --verbose --no-deps;
done
- for contract in ${UPGRADEABLE_CONTRACTS}; do
cargo doc --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml --document-private-items --verbose --no-deps;
done
- cargo doc --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml --document-private-items --verbose --no-deps
#### stage: ink-waterfall
ink-waterfall:
stage: ink-waterfall
image: paritytech/tools:latest
<<: *kubernetes-env
<<: *test-refs
variables:
TRGR_PROJECT: ${CI_PROJECT_NAME}
TRGR_REF: ${CI_COMMIT_REF_NAME}
# The `ink-waterfall` project id in GitLab
DWNSTRM_ID: 409
script:
- ./scripts/ci/trigger_pipeline.sh
allow_failure: true
#### stage: publish
publish-docs:
stage: publish
<<: *kubernetes-env
image: paritytech/tools:latest
needs:
- job: docs
artifacts: true
variables:
GIT_DEPTH: 100
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME == "tags"
before_script:
- unset CARGO_TARGET_DIR
script:
# Setup ssh
- eval $(ssh-agent)
- ssh-add - <<< ${GITHUB_SSH_PRIV_KEY}
- mkdir ~/.ssh && touch ~/.ssh/known_hosts
- ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# Set git config
- git config user.email "${GITHUB_EMAIL}"
- git config user.name "${GITHUB_USER}"
- git config remote.origin.url "[email protected]:/paritytech/${CI_PROJECT_NAME}.git"
- git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
- git fetch origin gh-pages
# saving README and docs
- cp -r ./crate-docs/ /tmp/doc/
- cp ./README.md /tmp/doc/
- cp -r ./.images/ /tmp/doc/
- git checkout gh-pages
- mv _config.yml /tmp/doc/
# remove everything and restore generated docs, README and Jekyll config
- rm -rf ./*
- rm -rf ./.images
- mv /tmp/doc/* .
- mv /tmp/doc/.images .
# Upload files
- git add --all --force
- git status
# `git commit` has an exit code of > 0 if there is nothing to commit.
# This unfortunately causes GitLab to exit immediately and mark this
# job as failed subsequently.
# We don't want to mark the entire job as failed if there's nothing to
# publish though, hence the `|| true`.
- git commit -m "Updated docs for ${CI_COMMIT_REF_NAME} and pushed to gh-pages" || true
- git push origin gh-pages --force
after_script:
- rm -rf .git/ ./*
#### stage: fuzz
fuzz-tests:
stage: fuzz
<<: *docker-env
variables:
# The QUICKCHECK_TESTS default is 100
QUICKCHECK_TESTS: 5000
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
script:
# We fuzz-test only crates which possess the `ink-fuzz-tests` feature
- all_tests_passed=0
- for crate in ${ALL_CRATES}; do
if grep "ink-fuzz-tests =" ./crates/${crate}/Cargo.toml;
then
cargo test --verbose --features ink-fuzz-tests --manifest-path ./crates/${crate}/Cargo.toml --no-fail-fast -- fuzz_ || exit_code=$?;
all_tests_passed=$(( all_tests_passed | exit_code ));
fi
done
- if [ $all_tests_passed -eq 0 ]; then exit 0; fi
- |
curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues" \
-H "Cookie: logged_in=no" \
-H "Authorization: token ${GITHUB_PR_TOKEN}" \
-H "Content-Type: application/json; charset=utf-8" \
-d $'{
"title": "[ci] Failing fuzz tests on master ('"$( date +"%d %b %Y" )"')",
"body": "The CI job ['"${CI_JOB_ID}"']('"${CI_JOB_URL}"') just failed.\n\nThe offending commit is ['"${CI_COMMIT_TITLE}"'](https://github.com/paritytech/ink/commit/'"${CI_COMMIT_SHA}"').",
"assignees": [],
"labels": [
"P-high"
]
}'
- exit ${all_tests_passed}