.gitlab-ci.yml 15.7 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
  - ink-waterfall
13
  - fuzz
14
  - publish
Denis_P's avatar
Denis_P committed
15
16
17

variables:
  GIT_STRATEGY:                    fetch
Denis_P's avatar
Denis_P committed
18
  GIT_DEPTH:                       100
19
  CARGO_INCREMENTAL:               0
Denis_P's avatar
Denis_P committed
20
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
21
  CI_IMAGE:                        "paritytech/ink-ci-linux:production"
22
23
  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
24
25
  # 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
26
  ALL_CRATES:                      "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
27
  DELEGATOR_SUBCONTRACTS:           "accumulator adder subber"
Denis_P's avatar
Denis_P committed
28

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

Denis_P's avatar
Denis_P committed
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/

42
43
44
45
46
.rust-info-script:                 &rust-info-script
  - rustup show
  - cargo --version
  - rustup +nightly show
  - cargo +nightly --version
47
  - cargo spellcheck --version
48
49
50
51
  - bash --version
  - sccache -s

.test-refs:                        &test-refs
52
53
54
55
56
  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
57
    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
58
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1
59
60
61
62
63
64
65

.docker-env:                       &docker-env
  image:                           "${CI_IMAGE}"
  before_script:
    - *rust-info-script
    - ./scripts/.ci/pre_cache.sh
    - sccache -s
Denis_P's avatar
Denis_P committed
66
  interruptible:                   true
67
68
  retry:
    max: 2
Denis_P's avatar
Denis_P committed
69
    when:
70
71
72
      - runner_system_failure
      - unknown_failure
      - api_failure
Denis_P's avatar
Denis_P committed
73
  tags:
74
    - linux-docker
Denis_P's avatar
Denis_P committed
75

76
77
78
79
80
81
82
83
84
85
.kubernetes-env:                   &kubernetes-env
  interruptible:                   true
  retry:
    max: 2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure
  tags:
    - kubernetes-parity-build
Denis_P's avatar
Denis_P committed
86
87

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

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

Hero Bird's avatar
Hero Bird committed
98
check-wasm:
Denis_P's avatar
Denis_P committed
99
  stage:                           check
Denis_P's avatar
Denis_P committed
100
  <<:                              *docker-env
101
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
102
  script:
103
    - for crate in ${ALSO_WASM_CRATES}; do
104
        cargo check --verbose --no-default-features --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
105
      done
Denis_P's avatar
Denis_P committed
106

107

Denis_P's avatar
Denis_P committed
108
109
#### stage:                        workspace

Hero Bird's avatar
Hero Bird committed
110
build-std:
Denis_P's avatar
Denis_P committed
111
  stage:                           workspace
Denis_P's avatar
Denis_P committed
112
  <<:                              *docker-env
113
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
114
  needs:
115
116
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
117
  script:
Hero Bird's avatar
Hero Bird committed
118
    - for crate in ${ALL_CRATES}; do
119
        cargo build --verbose --all-features --release --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
120
      done
Denis_P's avatar
Denis_P committed
121

Hero Bird's avatar
Hero Bird committed
122
build-wasm:
Denis_P's avatar
Denis_P committed
123
  stage:                           workspace
Denis_P's avatar
Denis_P committed
124
  <<:                              *docker-env
125
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
126
  needs:
127
128
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
129
  script:
130
    - for crate in ${ALSO_WASM_CRATES}; do
131
        cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
132
      done
Denis_P's avatar
Denis_P committed
133

Denis_P's avatar
Denis_P committed
134
135
test:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
136
  <<:                              *docker-env
137
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
138
  needs:
139
140
    - job:                         check-std
      artifacts:                   false
141
142
143
144
145
146
  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
147
  script:
148
    - cargo test --verbose --all-features --no-fail-fast --workspace
149
    - cargo test --verbose --all-features --no-fail-fast --workspace --doc
150

151
152
153
154
155
156
      # 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

157
158
159
docs:
  stage:                           workspace
  <<:                              *docker-env
160
  <<:                              *test-refs
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  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

177
spellcheck:
178
179
180
181
  stage:                           workspace
  <<:                              *docker-env
  <<:                              *test-refs
  script:
182
183
    - cargo spellcheck check -vvvv --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 -- recursive .
    - cargo spellcheck check -vvvv --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 -- recursive examples/
184

Hero Bird's avatar
Hero Bird committed
185
clippy-std:
Denis_P's avatar
Denis_P committed
186
  stage:                           workspace
Denis_P's avatar
Denis_P committed
187
  <<:                              *docker-env
188
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
189
  needs:
190
191
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
192
  script:
Hero Bird's avatar
Hero Bird committed
193
    - for crate in ${ALL_CRATES}; do
194
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
195
      done
Denis_P's avatar
Denis_P committed
196

Hero Bird's avatar
Hero Bird committed
197
clippy-wasm:
Denis_P's avatar
Denis_P committed
198
  stage:                           workspace
Denis_P's avatar
Denis_P committed
199
  <<:                              *docker-env
200
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
201
  needs:
202
203
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
204
  script:
205
    - for crate in ${ALSO_WASM_CRATES}; do
206
        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
207
208
209
      done

fmt:
Denis_P's avatar
Denis_P committed
210
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
211
  <<:                              *docker-env
212
  <<:                              *test-refs
Hero Bird's avatar
Hero Bird committed
213
  script:
Hero Bird's avatar
Hero Bird committed
214
    - cargo fmt --verbose --all -- --check
215
216
217
    # 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
218

Denis_P's avatar
Denis_P committed
219
#### stage:                        examples
Denis_P's avatar
Denis_P committed
220

Hero Bird's avatar
Hero Bird committed
221
examples-test:
Denis_P's avatar
Denis_P committed
222
  stage:                           examples
Denis_P's avatar
Denis_P committed
223
  <<:                              *docker-env
224
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
225
  needs:
226
227
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
228
  script:
229
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
230
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
231
      done
232
233
234
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        cargo test --verbose --manifest-path examples/delegator/${contract}/Cargo.toml;
      done
Denis_P's avatar
Denis_P committed
235

236
237
238
examples-test-experimental-engine:
  stage:                           examples
  <<:                              *docker-env
239
  <<:                              *test-refs
240
241
242
243
244
245
246
  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
Hernando Castano's avatar
Hernando Castano committed
247
    - cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/erc1155/Cargo.toml
248
249
250
    - 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
251
examples-fmt:
Denis_P's avatar
Denis_P committed
252
  stage:                           examples
Denis_P's avatar
Denis_P committed
253
  <<:                              *docker-env
254
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
255
  script:
256
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
257
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
258
      done
259
260
261
    - 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
262

Hero Bird's avatar
Hero Bird committed
263
examples-clippy-std:
Denis_P's avatar
Denis_P committed
264
  stage:                           examples
Denis_P's avatar
Denis_P committed
265
  <<:                              *docker-env
266
  <<:                              *test-refs
Denis_P's avatar
Denis_P committed
267
  needs:
268
269
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
270
  script:
271
    - for example in examples/*/; do
272
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
273
      done
274
275
276
    - 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
277
278
279
280

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
281
  <<:                              *test-refs
Hero Bird's avatar
Hero Bird committed
282
  script:
283
    - for example in examples/*/; do
284
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
285
      done
286
287
288
    - 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
289
290
291
292

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
293
  <<:                              *test-refs
Hero Bird's avatar
Hero Bird committed
294
  script:
295
    - cargo contract -V
296
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
297
298
299
300
        pushd $example &&
        cargo contract build &&
        popd;
      done
301
302
303
304
305
306
307
    - for contract in ${DELEGATOR_SUBCONTRACTS}; do
        pushd examples/delegator/$contract &&
        cargo contract build &&
        popd;
      done

examples-contract-build-delegator:
308
309
310
    stage:                         examples
    <<:                            *docker-env
    <<:                            *test-refs
311
312
313
    script:
        - cargo contract -V
        - cd examples/delegator/ && ./build-all.sh
Hero Bird's avatar
Hero Bird committed
314

315
examples-docs:
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
  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
        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
332

333
334
335
336
337

#### stage:                        ink-waterfall

ink-waterfall:
  stage:                           ink-waterfall
338
339
340
  image:                           paritytech/tools:latest
  <<:                              *kubernetes-env
  <<:                              *test-refs
341
  variables:
342
343
344
345
346
347
348
    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
349
350


Denis_P's avatar
Denis_P committed
351
352
353
354
355
#### stage:                        publish

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

#### stage:                        fuzz

fuzz-tests:
408
409
410
411
412
  stage:                           fuzz
  <<:                              *docker-env
  <<:                              *test-refs
  variables:
    # The QUICKCHECK_TESTS default is 100
413
    QUICKCHECK_TESTS:              5000
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
  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_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}