.gitlab-ci.yml 16.5 KB
Newer Older
Denis_P's avatar
Denis_P committed
1
2
3
4
5
6
7
8
# .gitlab-ci.yml
#
# ink
#
# pipelines can be triggered manually in the web


stages:
Denis_P's avatar
Denis_P committed
9
10
  - check
  - workspace
Denis_P's avatar
Denis_P committed
11
  - examples
12
  - fuzz
13
  - publish
Denis_P's avatar
Denis_P committed
14
15
16

variables:
  GIT_STRATEGY:                    fetch
Denis_P's avatar
Denis_P committed
17
  GIT_DEPTH:                       100
18
  CARGO_INCREMENTAL:               0
Denis_P's avatar
Denis_P committed
19
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
20
  CI_IMAGE:                        "paritytech/ink-ci-linux:production"
21
22
  PURELY_STD_CRATES:               "lang/codegen metadata"
  ALSO_WASM_CRATES:                "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
Denis_P's avatar
Denis_P committed
23
24
  # this var is changed to "-:staging" when the CI image gets rebuilt
  # read more https://github.com/paritytech/scripts/pull/244
Michael Müller's avatar
Michael Müller committed
25
  ALL_CRATES:                      "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
26
  DELEGATOR_SUBCONTRACTS:           "accumulator adder subber"
Denis_P's avatar
Denis_P committed
27

28
29
30
31
32
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

Denis_P's avatar
Denis_P committed
33
34
35
36
37
38
39
40
41
.collect-artifacts:                &collect-artifacts
  artifacts:
    name:                          "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    when:                          on_success
    expire_in:                     7 days
    paths:
      - artifacts/

.docker-env:                       &docker-env
Denis_P's avatar
Denis_P committed
42
  image:                           "${CI_IMAGE}"
Denis_P's avatar
Denis_P committed
43
  before_script:
Denis_P's avatar
Denis_P committed
44
45
    - cargo -vV
    - rustc -vV
Denis_P's avatar
Denis_P committed
46
    - rustup show
Denis_P's avatar
Denis_P committed
47
    - bash --version
Denis_P's avatar
Denis_P committed
48
    - ./scripts/pre_cache.sh
Denis_P's avatar
Denis_P committed
49
    - sccache -s
50
51
52
53
54
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_COMMIT_REF_NAME == "master"
    - if: $CI_COMMIT_REF_NAME == "tags"
Denis_P's avatar
Denis_P committed
55
    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
56
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1
Denis_P's avatar
Denis_P committed
57
  interruptible:                   true
58
59
  retry:
    max: 2
Denis_P's avatar
Denis_P committed
60
    when:
61
62
63
      - runner_system_failure
      - unknown_failure
      - api_failure
Denis_P's avatar
Denis_P committed
64
  tags:
65
    - linux-docker
Denis_P's avatar
Denis_P committed
66

Denis_P's avatar
Denis_P committed
67
68

#### stage:                        check
Denis_P's avatar
Denis_P committed
69

Hero Bird's avatar
Hero Bird committed
70
check-std:
Denis_P's avatar
Denis_P committed
71
  stage:                           check
Denis_P's avatar
Denis_P committed
72
73
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
74
    - for crate in ${ALL_CRATES}; do
75
        cargo check --verbose --all-features --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
76
      done
Denis_P's avatar
Denis_P committed
77

Hero Bird's avatar
Hero Bird committed
78
check-wasm:
Denis_P's avatar
Denis_P committed
79
  stage:                           check
Denis_P's avatar
Denis_P committed
80
81
  <<:                              *docker-env
  script:
82
    - for crate in ${ALSO_WASM_CRATES}; do
83
        cargo check --verbose --no-default-features --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
84
      done
Denis_P's avatar
Denis_P committed
85

86

Denis_P's avatar
Denis_P committed
87
88
#### stage:                        workspace

Hero Bird's avatar
Hero Bird committed
89
build-std:
Denis_P's avatar
Denis_P committed
90
  stage:                           workspace
Denis_P's avatar
Denis_P committed
91
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
92
  needs:
93
94
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
95
  script:
Hero Bird's avatar
Hero Bird committed
96
    - for crate in ${ALL_CRATES}; do
97
        cargo build --verbose --all-features --release --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
98
      done
Denis_P's avatar
Denis_P committed
99

Hero Bird's avatar
Hero Bird committed
100
build-wasm:
Denis_P's avatar
Denis_P committed
101
  stage:                           workspace
Denis_P's avatar
Denis_P committed
102
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
103
  needs:
104
105
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
106
  script:
107
    - for crate in ${ALSO_WASM_CRATES}; do
108
        cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
109
      done
Denis_P's avatar
Denis_P committed
110

Denis_P's avatar
Denis_P committed
111
112
test:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
113
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
114
  needs:
115
116
    - job:                         check-std
      artifacts:                   false
117
118
119
120
121
122
  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
Denis_P's avatar
Denis_P committed
123
  script:
124
    - cargo test --verbose --all-features --no-fail-fast --workspace
125
    - cargo test --verbose --all-features --no-fail-fast --workspace --doc
126

127
128
129
130
131
132
      # Just needed as long as we have the `ink-experimental-engine` feature.
      # We do not invoke `--all-features` here -- this would imply the feature
      # `ink-experimental-engine`. So in order to still run the tests without the
      # experimental engine feature we need this command.
    - cargo test --verbose --features std --no-fail-fast --workspace

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
docs:
  stage:                           workspace
  <<:                              *docker-env
  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

152
153
154
155
156
spellcheck:
    stage:                           workspace
    <<:                              *docker-env
    script:
        - cargo spellcheck check --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1
157
158
159
160
161
162
        - for example in examples/*/; do
            cargo spellcheck check --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 ${example};
          done
        - for contract in ${DELEGATOR_SUBCONTRACTS}; do
            cargo spellcheck check --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 examples/delegator/${contract}/;
          done
163

164
165
166
167
codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
168
169
    - job:                         check-std
      artifacts:                   false
170
  variables:
171
    # For codecov it's sufficient to run the fuzz tests only once.
172
    QUICKCHECK_TESTS:              1
Denis_P's avatar
Denis_P committed
173
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
174
    CARGO_INCREMENTAL:             0
175
176
    RUSTFLAGS:                     "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1
                                      -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"
Denis_P's avatar
Denis_P committed
177
178
179
    # 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.
Denis_P's avatar
Denis_P committed
180
181
182
183
184
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
185
186
    - unset "CARGO_TARGET_DIR"
    - cargo clean
Denis_P's avatar
Denis_P committed
187
188
  script:
    # RUSTFLAGS are the cause target cache can't be used here
189
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
190
    - cargo test --verbose --all-features --no-fail-fast --workspace
191
192
193
194
195
196
197

    # Just needed as long as we have the `ink-experimental-engine` feature.
    # We must additionally run the coverage without `--all-features` here -- this
    # would imply the feature `ink-experimental-engine`. So in order to still run
    # the tests without the experimental engine feature we need this command.
    - cargo test --verbose --features std --no-fail-fast --workspace

Denis_P's avatar
Denis_P committed
198
    # coverage with branches
Denis_P's avatar
Denis_P committed
199
200
201
    - grcov . --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
202
203
    # We'd like to not use a remote bash script for uploading the coverage reports,
    # however this job seems to be more tricky than we hoped.
Denis_P's avatar
Denis_P committed
204
    - bash <(curl -s https://codecov.io/bash) -t "$CODECOV_P_TOKEN" -f lcov-w-branch-fixed.info
Denis_P's avatar
Denis_P committed
205
    # lines coverage
Denis_P's avatar
Denis_P committed
206
207
208
209
    - grcov . --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
    - bash <(curl -s https://codecov.io/bash) -f lcov-lines-fixed.info
Denis_P's avatar
Denis_P committed
210

Hero Bird's avatar
Hero Bird committed
211
clippy-std:
Denis_P's avatar
Denis_P committed
212
  stage:                           workspace
Denis_P's avatar
Denis_P committed
213
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
214
  needs:
215
216
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
217
  script:
Hero Bird's avatar
Hero Bird committed
218
    - for crate in ${ALL_CRATES}; do
219
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
220
      done
Denis_P's avatar
Denis_P committed
221

Hero Bird's avatar
Hero Bird committed
222
clippy-wasm:
Denis_P's avatar
Denis_P committed
223
  stage:                           workspace
Denis_P's avatar
Denis_P committed
224
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
225
  needs:
226
227
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
228
  script:
229
    - for crate in ${ALSO_WASM_CRATES}; do
230
        cargo clippy --verbose --no-default-features --manifest-path crates/${crate}/Cargo.toml --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
231
232
233
      done

fmt:
Denis_P's avatar
Denis_P committed
234
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
235
236
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
237
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
238

239
240
241
    # For the UI tests we need to disable the license check
    - cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/macro/tests/ui/{pass,fail}/*.rs

Denis_P's avatar
Denis_P committed
242

Denis_P's avatar
Denis_P committed
243
#### stage:                        examples
Denis_P's avatar
Denis_P committed
244

Hero Bird's avatar
Hero Bird committed
245
examples-test:
Denis_P's avatar
Denis_P committed
246
  stage:                           examples
Denis_P's avatar
Denis_P committed
247
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
248
  needs:
249
250
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
251
  script:
252
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
253
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
254
      done
255
256
257
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        cargo test --verbose --manifest-path examples/delegator/${contract}/Cargo.toml;
      done
Denis_P's avatar
Denis_P committed
258

259
260
261
262
263
264
265
266
267
268
269
270
271
examples-test-experimental-engine:
  stage:                           examples
  <<:                              *docker-env
  needs:
    - job:                         clippy-std
      artifacts:                   false
  script:
    # We test only the examples for which the tests have already been migrated to
    # use the experimental engine.
    - cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/erc20/Cargo.toml
    - cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/contract-terminate/Cargo.toml
    - cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/contract-transfer/Cargo.toml

Hero Bird's avatar
Hero Bird committed
272
examples-fmt:
Denis_P's avatar
Denis_P committed
273
  stage:                           examples
Denis_P's avatar
Denis_P committed
274
275
  <<:                              *docker-env
  script:
276
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
277
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
278
      done
279
280
281
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        cargo fmt --verbose --manifest-path examples/delegator/${contract}/Cargo.toml -- --check;
      done
Denis_P's avatar
Denis_P committed
282

Hero Bird's avatar
Hero Bird committed
283
examples-clippy-std:
Denis_P's avatar
Denis_P committed
284
  stage:                           examples
Denis_P's avatar
Denis_P committed
285
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
286
  needs:
287
288
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
289
  script:
290
    - for example in examples/*/; do
291
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
292
      done
293
294
295
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        cargo clippy --verbose --manifest-path examples/delegator/${contract}/Cargo.toml -- -D warnings;
      done
Hero Bird's avatar
Hero Bird committed
296
297
298
299
300

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
301
    - for example in examples/*/; do
302
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
303
      done
304
305
306
    - 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
Hero Bird's avatar
Hero Bird committed
307
308
309
310
311

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
312
    - cargo contract -V
313
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
314
315
316
317
        pushd $example &&
        cargo contract build &&
        popd;
      done
318
319
320
321
322
323
324
325
326
327
328
329
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        pushd examples/delegator/$contract &&
        cargo contract build &&
        popd;
      done

examples-contract-build-delegator:
    stage:                           examples
    <<:                              *docker-env
    script:
        - cargo contract -V
        - cd examples/delegator/ && ./build-all.sh
Hero Bird's avatar
Hero Bird committed
330

331
332
333
334
335
336
337
338
339
340
341
342
343
examples-docs:
    stage:                           examples
    <<:                              *docker-env
    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
            cargo doc --manifest-path ${example}/Cargo.toml --document-private-items --verbose --no-deps;
          done
344
345
346
        - for contract in ${DELEGATOR_SUBCONTRACTS}; do
            cargo doc --manifest-path examples/delegator/${contract}/Cargo.toml --document-private-items --verbose --no-deps;
          done
347

Denis_P's avatar
Denis_P committed
348
349
350
351
352
#### stage:                        publish

publish-docs:
  stage:                           publish
  <<:                              *docker-env
353
354
355
  needs:
    - job:                       docs
      artifacts:                 true
Denis_P's avatar
Denis_P committed
356
  variables:
Denis_P's avatar
Denis_P committed
357
    GIT_DEPTH:                   100
358
359
360
361
362
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_COMMIT_REF_NAME == "master"
    - if: $CI_COMMIT_REF_NAME == "tags"
363
364
365
366
  # need to overwrite `before_script` from `*docker-env` here,
  # this branch does not have a `./scripts/pre_cache.sh`
  before_script:
    - unset CARGO_TARGET_DIR
Denis_P's avatar
Denis_P committed
367
  script:
Denis_P's avatar
Denis_P committed
368
    - rm -rf /tmp/*
Denis_P's avatar
Denis_P committed
369
    # Set git config
Denis_P's avatar
Denis_P committed
370
    - rm -rf .git/config
Denis_P's avatar
Denis_P committed
371
372
    - git config user.email "devops-team@parity.io"
    - git config user.name "${GITHUB_USER}"
Denis_P's avatar
Denis_P committed
373
    - git config remote.origin.url "https://${GITHUB_TOKEN}@github.com/paritytech/ink.git"
Denis_P's avatar
Denis_P committed
374
375
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
Denis_P's avatar
Denis_P committed
376
    # saving README and docs
377
    - cp -r ./crate-docs/ /tmp/doc/
Denis_P's avatar
Denis_P committed
378
    - cp README.md /tmp/doc/
379
    - cp -r .images/ /tmp/doc/
Denis_P's avatar
Denis_P committed
380
    - git checkout gh-pages
Denis_P's avatar
Denis_P committed
381
382
    - mv _config.yml /tmp/doc/
    # remove everything and restore generated docs, README and Jekyll config
Denis_P's avatar
Denis_P committed
383
    - rm -rf ./*
384
    - rm -rf ./.images
Denis_P's avatar
Denis_P committed
385
    - mv /tmp/doc/* .
386
    - mv /tmp/doc/.images .
Denis_P's avatar
Denis_P committed
387
    # Upload files
Denis_P's avatar
Denis_P committed
388
    - git add --all --force
Denis_P's avatar
Denis_P committed
389
    - git status
Michael Müller's avatar
Michael Müller committed
390
391
392
393
394
395
    # `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
Denis_P's avatar
Denis_P committed
396
    - git push origin gh-pages --force
Denis_P's avatar
Denis_P committed
397
398
  after_script:
    - rm -rf .git/ ./*
399
400
401
402
403
404
405
406

#### stage:                        fuzz

fuzz-tests:
    stage:                           fuzz
    <<:                              *docker-env
    variables:
        # The QUICKCHECK_TESTS default is 100
407
        QUICKCHECK_TESTS:            20000
408
409
410
411
412
413
414
415
416
    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
417
                cargo test --verbose --features ink-fuzz-tests --manifest-path crates/${crate}/Cargo.toml --no-fail-fast -- fuzz_ || exit_code=$?;
Michael Müller's avatar
Michael Müller committed
418
                all_tests_passed=$(( all_tests_passed | exit_code ));
419
420
421
422
            fi
          done
        - if [ $all_tests_passed -eq 0 ]; then exit 0; fi
        - |
Michael Müller's avatar
Michael Müller committed
423
             curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues" \
424
425
                -H "Cookie: logged_in=no" \
                -H "Authorization: token ${GITHUB_TOKEN}" \
Michael Müller's avatar
Michael Müller committed
426
                -H "Content-Type: application/json; charset=utf-8" \
427
                -d $'{
Michael Müller's avatar
Michael Müller committed
428
429
                    "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}"').",
430
431
432
433
434
                    "assignees": [],
                    "labels": [
                        "P-high"
                    ]
                }'
Michael Müller's avatar
Michael Müller committed
435
        - exit ${all_tests_passed}