.gitlab-ci.yml 12.9 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}"
Denis_P's avatar
Denis_P committed
26

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

Denis_P's avatar
Denis_P committed
32
33
34
35
36
37
38
39
40
.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
41
  image:                           "${CI_IMAGE}"
Denis_P's avatar
Denis_P committed
42
  before_script:
Denis_P's avatar
Denis_P committed
43
44
    - cargo -vV
    - rustc -vV
Denis_P's avatar
Denis_P committed
45
    - rustup show
Denis_P's avatar
Denis_P committed
46
    - bash --version
Denis_P's avatar
Denis_P committed
47
    - ./scripts/pre_cache.sh
Denis_P's avatar
Denis_P committed
48
    - sccache -s
49
50
51
52
53
  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
54
    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
55
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1
Denis_P's avatar
Denis_P committed
56
  interruptible:                   true
57
58
  retry:
    max: 2
Denis_P's avatar
Denis_P committed
59
    when:
60
61
62
      - runner_system_failure
      - unknown_failure
      - api_failure
Denis_P's avatar
Denis_P committed
63
  tags:
64
    - linux-docker
Denis_P's avatar
Denis_P committed
65

Denis_P's avatar
Denis_P committed
66
67

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

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

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

85

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

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

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

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

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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

144
145
146
147
codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
148
149
    - job:                         check-std
      artifacts:                   false
150
  variables:
151
    # For codecov it's sufficient to run the fuzz tests only once.
152
    QUICKCHECK_TESTS:              1
Denis_P's avatar
Denis_P committed
153
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
154
    CARGO_INCREMENTAL:             0
155
156
    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
157
158
159
    # 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
160
161
162
163
164
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
165
166
    - unset "CARGO_TARGET_DIR"
    - cargo clean
Denis_P's avatar
Denis_P committed
167
168
  script:
    # RUSTFLAGS are the cause target cache can't be used here
169
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
170
    - cargo test --verbose --all-features --no-fail-fast --workspace
Denis_P's avatar
Denis_P committed
171
    # coverage with branches
Denis_P's avatar
Denis_P committed
172
173
174
    - 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
175
176
    # 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
177
    - bash <(curl -s https://codecov.io/bash) -t "$CODECOV_P_TOKEN" -f lcov-w-branch-fixed.info
Denis_P's avatar
Denis_P committed
178
    # lines coverage
Denis_P's avatar
Denis_P committed
179
180
181
182
    - 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
183

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

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

fmt:
Denis_P's avatar
Denis_P committed
207
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
208
209
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
210
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
211

212
213
214
    # 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
215

Denis_P's avatar
Denis_P committed
216
#### stage:                        examples
Denis_P's avatar
Denis_P committed
217

Hero Bird's avatar
Hero Bird committed
218
examples-test:
Denis_P's avatar
Denis_P committed
219
  stage:                           examples
Denis_P's avatar
Denis_P committed
220
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
221
  needs:
222
223
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
224
  script:
225
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
226
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
227
228
      done

Hero Bird's avatar
Hero Bird committed
229
examples-fmt:
Denis_P's avatar
Denis_P committed
230
  stage:                           examples
Denis_P's avatar
Denis_P committed
231
232
  <<:                              *docker-env
  script:
233
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
234
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
235
236
      done

Hero Bird's avatar
Hero Bird committed
237
examples-clippy-std:
Denis_P's avatar
Denis_P committed
238
  stage:                           examples
Denis_P's avatar
Denis_P committed
239
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
240
  needs:
241
242
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
243
  script:
244
    # Revert as soon as the clippy nightly ice fix lands
245
    - for example in examples/*/; do
246
        if [ "$example" != "examples/rand-extension/" ]; then
247
248
            cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
        fi
Hero Bird's avatar
Hero Bird committed
249
250
251
252
253
254
      done

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
255
    # Revert as soon as the clippy nightly ice fix lands
256
    - for example in examples/*/; do
257
        if [ "$example" != "examples/rand-extension/" ]; then
258
259
            cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
        fi
Hero Bird's avatar
Hero Bird committed
260
261
262
263
264
265
      done

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
266
    - cargo contract -V
267
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
268
269
270
271
272
        pushd $example &&
        cargo contract build &&
        popd;
      done

273
274
275
276
277
278
279
280
281
282
283
284
285
286
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

Denis_P's avatar
Denis_P committed
287
288
289
290
291
#### stage:                        publish

publish-docs:
  stage:                           publish
  <<:                              *docker-env
292
293
294
  needs:
    - job:                       docs
      artifacts:                 true
Denis_P's avatar
Denis_P committed
295
296
  variables:
    GIT_DEPTH:                     0
297
    GIT_STRATEGY:                  none
298
299
300
301
302
  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
303
  script:
Denis_P's avatar
Denis_P committed
304
305
    - rm -rf /tmp/*
    - unset CARGO_TARGET_DIR
Denis_P's avatar
Denis_P committed
306
307
308
309
    # Set git config
    - rm .git/config
    - git config user.email "devops-team@parity.io"
    - git config user.name "${GITHUB_USER}"
Denis_P's avatar
Denis_P committed
310
    - git config remote.origin.url "https://${GITHUB_TOKEN}@github.com/paritytech/ink.git"
Denis_P's avatar
Denis_P committed
311
312
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
Denis_P's avatar
Denis_P committed
313
    # saving README and docs
314
    - cp -r ./crate-docs/ /tmp/doc/
Denis_P's avatar
Denis_P committed
315
    - cp README.md /tmp/doc/
316
    - cp -r .images/ /tmp/doc/
Denis_P's avatar
Denis_P committed
317
    - git checkout gh-pages
Denis_P's avatar
Denis_P committed
318
319
    - mv _config.yml /tmp/doc/
    # remove everything and restore generated docs, README and Jekyll config
Denis_P's avatar
Denis_P committed
320
    - rm -rf ./*
321
    - rm -rf ./.images
Denis_P's avatar
Denis_P committed
322
    - mv /tmp/doc/* .
323
    - mv /tmp/doc/.images .
Denis_P's avatar
Denis_P committed
324
    # Upload files
Denis_P's avatar
Denis_P committed
325
    - git add --all --force
Denis_P's avatar
Denis_P committed
326
    - git status
Denis_P's avatar
Denis_P committed
327
    - git commit -m "Updated docs for ${CI_COMMIT_REF_NAME} and pushed to gh-pages"
Denis_P's avatar
Denis_P committed
328
    - git push origin gh-pages --force
Denis_P's avatar
Denis_P committed
329
330
  after_script:
    - rm -rf .git/ ./*
331
332
333
334
335
336
337
338

#### stage:                        fuzz

fuzz-tests:
    stage:                           fuzz
    <<:                              *docker-env
    variables:
        # The QUICKCHECK_TESTS default is 100
339
        QUICKCHECK_TESTS:            40000
340
341
342
343
344
345
346
347
348
    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
349
                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
350
                all_tests_passed=$(( all_tests_passed | exit_code ));
351
352
353
354
            fi
          done
        - if [ $all_tests_passed -eq 0 ]; then exit 0; fi
        - |
Michael Müller's avatar
Michael Müller committed
355
             curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues" \
356
357
                -H "Cookie: logged_in=no" \
                -H "Authorization: token ${GITHUB_TOKEN}" \
Michael Müller's avatar
Michael Müller committed
358
                -H "Content-Type: application/json; charset=utf-8" \
359
                -d $'{
Michael Müller's avatar
Michael Müller committed
360
361
                    "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}"').",
362
363
364
365
366
                    "assignees": [],
                    "labels": [
                        "P-high"
                    ]
                }'
Michael Müller's avatar
Michael Müller committed
367
        - exit ${all_tests_passed}