.gitlab-ci.yml 11.4 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"
Denis_P's avatar
Denis_P committed
52
    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
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

190
191
192
    # 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
193

Denis_P's avatar
Denis_P committed
194
#### stage:                        examples
Denis_P's avatar
Denis_P committed
195

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

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

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

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

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
238
    - cargo contract -V
239
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
240
241
242
243
244
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
245
246
247
248
249
#### stage:                        publish

publish-docs:
  stage:                           publish
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
250
251
  variables:
    GIT_DEPTH:                     0
252
253
254
255
256
  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
257
  script:
Denis_P's avatar
Denis_P committed
258
259
    - rm -rf /tmp/*
    - unset CARGO_TARGET_DIR
Denis_P's avatar
Denis_P committed
260
261
262
263
    # 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
264
    - git config remote.origin.url "https://${GITHUB_TOKEN}@github.com/paritytech/ink.git"
Denis_P's avatar
Denis_P committed
265
266
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
Denis_P's avatar
Denis_P committed
267
    # Generating Docs
Denis_P's avatar
Denis_P committed
268
    - time cargo doc --no-deps --all-features
269
270
271
272
        -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
273
274
275
    # saving README and docs
    - mv target/doc/ /tmp/
    - cp README.md /tmp/doc/
Denis_P's avatar
Denis_P committed
276
    - git checkout gh-pages
Denis_P's avatar
Denis_P committed
277
278
    - mv _config.yml /tmp/doc/
    # remove everything and restore generated docs, README and Jekyll config
Denis_P's avatar
Denis_P committed
279
    - rm -rf ./*
Denis_P's avatar
Denis_P committed
280
    - mv /tmp/doc/* .
Denis_P's avatar
Denis_P committed
281
    # Upload files
Denis_P's avatar
Denis_P committed
282
    - git add --all --force
Denis_P's avatar
Denis_P committed
283
    - git status
Denis_P's avatar
Denis_P committed
284
    - git commit -m "Updated docs for ${CI_COMMIT_REF_NAME} and pushed to gh-pages"
Denis_P's avatar
Denis_P committed
285
    - git push origin gh-pages --force
Denis_P's avatar
Denis_P committed
286
287
  after_script:
    - rm -rf .git/ ./*
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

#### 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
306
                cargo test --verbose --features ink-fuzz-tests --manifest-path crates/${crate}/Cargo.toml --no-fail-fast -- fuzz_;
307
                all_tests_passed=$(( all_tests_passed | $? ));
308
309
310
311
            fi
          done
        - if [ $all_tests_passed -eq 0 ]; then exit 0; fi
        - |
Michael Müller's avatar
Michael Müller committed
312
             curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues" \
313
314
                -H "Cookie: logged_in=no" \
                -H "Authorization: token ${GITHUB_TOKEN}" \
Michael Müller's avatar
Michael Müller committed
315
                -H "Content-Type: application/json; charset=utf-8" \
316
                -d $'{
Michael Müller's avatar
Michael Müller committed
317
318
                    "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}"').",
319
320
321
322
323
                    "assignees": [],
                    "labels": [
                        "P-high"
                    ]
                }'
Michael Müller's avatar
Michael Müller committed
324
        - exit ${all_tests_passed}