.gitlab-ci.yml 12 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_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
20
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
21
22
  PURELY_STD_CRATES:               "lang/codegen metadata"
  ALSO_WASM_CRATES:                "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
Michael Müller's avatar
Michael Müller committed
23
  ALL_CRATES:                      "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
Denis_P's avatar
Denis_P committed
24

25
26
27
28
29
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

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

Denis_P's avatar
Denis_P committed
64
65

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

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

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

Denis_P's avatar
Denis_P committed
83

Denis_P's avatar
Denis_P committed
84
85
#### stage:                        workspace

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

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

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

codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
127
128
    - job:                         check-std
      artifacts:                   false
129
  variables:
130
    # For codecov it's sufficient to run the fuzz tests only once.
131
    QUICKCHECK_TESTS:              1
Denis_P's avatar
Denis_P committed
132
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
133
    CARGO_INCREMENTAL:             0
134
135
    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
136
137
138
    # 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
139
140
141
142
143
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
144
    - unset "CARGO_TARGET_DIR"
Denis_P's avatar
Denis_P committed
145
    - unset "CARGO_HOME"
146
    - cargo clean
Denis_P's avatar
Denis_P committed
147
148
  script:
    # RUSTFLAGS are the cause target cache can't be used here
149
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
150
    - cargo test --verbose --all-features --no-fail-fast --workspace
Denis_P's avatar
Denis_P committed
151
152
153
    # coverage with branches
    - grcov ./target -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov-w-branch.info
    - rust-covfix -o lcov-w-branch.info lcov-w-branch.info
154
155
    # 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
156
157
158
159
160
    - bash <(curl -s https://codecov.io/bash) -t "$CODECOV_P_TOKEN" -f lcov-w-branch.info
    # lines coverage
    - grcov ./target -s . -t lcov --llvm --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov-lines.info
    - rust-covfix -o lcov-lines.info lcov-lines.info
    - bash <(curl -s https://codecov.io/bash) -f lcov-lines.info
Denis_P's avatar
Denis_P committed
161

Hero Bird's avatar
Hero Bird committed
162
clippy-std:
Denis_P's avatar
Denis_P committed
163
  stage:                           workspace
Denis_P's avatar
Denis_P committed
164
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
165
  needs:
166
167
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
168
  script:
Hero Bird's avatar
Hero Bird committed
169
    - for crate in ${ALL_CRATES}; do
170
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
171
      done
Denis_P's avatar
Denis_P committed
172

Hero Bird's avatar
Hero Bird committed
173
clippy-wasm:
Denis_P's avatar
Denis_P committed
174
  stage:                           workspace
Denis_P's avatar
Denis_P committed
175
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
176
  needs:
177
178
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
179
  script:
180
    - for crate in ${ALSO_WASM_CRATES}; do
181
        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
182
183
184
      done

fmt:
Denis_P's avatar
Denis_P committed
185
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
186
187
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
188
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
189

Denis_P's avatar
Denis_P committed
190

Denis_P's avatar
Denis_P committed
191
#### stage:                        examples
Denis_P's avatar
Denis_P committed
192

Denis_P's avatar
Denis_P committed
193
.update-cargo-contract:            &update-cargo-contract
194
195
196
197
  # `cargo install` returns an error if there is nothing to update, so have to suppress it here temporarily
# restore this once ink! 3.0 is published and the new version of cargo-contract has been released to crates.io
#  - cargo install cargo-contract || echo $?
  - cargo install --git https://github.com/paritytech/cargo-contract --tag ink-ci || echo $?
Denis_P's avatar
Denis_P committed
198
199
  - cargo contract -V

Hero Bird's avatar
Hero Bird committed
200
examples-test:
Denis_P's avatar
Denis_P committed
201
  stage:                           examples
Denis_P's avatar
Denis_P committed
202
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
203
  needs:
204
205
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
206
  script:
207
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
208
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
209
210
      done

Hero Bird's avatar
Hero Bird committed
211
examples-fmt:
Denis_P's avatar
Denis_P committed
212
  stage:                           examples
Denis_P's avatar
Denis_P committed
213
214
  <<:                              *docker-env
  script:
215
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
216
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
217
218
      done

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

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
234
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
235
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
236
237
238
239
240
241
      done

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
Denis_P's avatar
Denis_P committed
242
    - *update-cargo-contract
243
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
244
245
246
247
248
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
249
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
250
251
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
252
  needs:
253
254
    - job:                         build-wasm
      artifacts:                   false
Hero Bird's avatar
Hero Bird committed
255
  script:
Denis_P's avatar
Denis_P committed
256
    - *update-cargo-contract
257
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
258
        pushd $example &&
Denis_P's avatar
Denis_P committed
259
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
260
        popd;
Denis_P's avatar
Denis_P committed
261
      done
Denis_P's avatar
Denis_P committed
262
263
264
265
266
267

#### stage:                        publish

publish-docs:
  stage:                           publish
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
268
269
  variables:
    GIT_DEPTH:                     0
270
271
272
273
274
  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
275
  script:
Denis_P's avatar
Denis_P committed
276
277
    - rm -rf /tmp/*
    - unset CARGO_TARGET_DIR
Denis_P's avatar
Denis_P committed
278
279
280
281
    # 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
282
    - git config remote.origin.url "https://${GITHUB_TOKEN}@github.com/paritytech/ink.git"
Denis_P's avatar
Denis_P committed
283
284
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
Denis_P's avatar
Denis_P committed
285
    # Generating Docs
Denis_P's avatar
Denis_P committed
286
    - time cargo doc --no-deps --all-features
287
288
289
290
        -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
Denis_P's avatar
Denis_P committed
291
292
293
    # saving README and docs
    - mv target/doc/ /tmp/
    - cp README.md /tmp/doc/
Denis_P's avatar
Denis_P committed
294
    - git checkout gh-pages
Denis_P's avatar
Denis_P committed
295
296
    - mv _config.yml /tmp/doc/
    # remove everything and restore generated docs, README and Jekyll config
Denis_P's avatar
Denis_P committed
297
    - rm -rf ./*
Denis_P's avatar
Denis_P committed
298
    - mv /tmp/doc/* .
Denis_P's avatar
Denis_P committed
299
    # Upload files
Denis_P's avatar
Denis_P committed
300
    - git add --all --force
Denis_P's avatar
Denis_P committed
301
    - git status
Denis_P's avatar
Denis_P committed
302
    - git commit -m "Updated docs for ${CI_COMMIT_REF_NAME} and pushed to gh-pages"
Denis_P's avatar
Denis_P committed
303
    - git push origin gh-pages --force
Denis_P's avatar
Denis_P committed
304
305
  after_script:
    - rm -rf .git/ ./*
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

#### stage:                        fuzz

fuzz-tests:
    stage:                           fuzz
    <<:                              *docker-env
    variables:
        # The QUICKCHECK_TESTS default is 100
        QUICKCHECK_TESTS:            50000
    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
324
                cargo test --verbose --features ink-fuzz-tests --manifest-path crates/${crate}/Cargo.toml --no-fail-fast -- fuzz_;
325
                all_tests_passed=$(( all_tests_passed | $? ));
326
327
328
329
            fi
          done
        - if [ $all_tests_passed -eq 0 ]; then exit 0; fi
        - |
Michael Müller's avatar
Michael Müller committed
330
             curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues" \
331
332
                -H "Cookie: logged_in=no" \
                -H "Authorization: token ${GITHUB_TOKEN}" \
Michael Müller's avatar
Michael Müller committed
333
                -H "Content-Type: application/json; charset=utf-8" \
334
                -d $'{
Michael Müller's avatar
Michael Müller committed
335
336
                    "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}"').",
337
338
339
340
341
                    "assignees": [],
                    "labels": [
                        "P-high"
                    ]
                }'
Michael Müller's avatar
Michael Müller committed
342
        - exit ${all_tests_passed}