.gitlab-ci.yml 9.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
Denis_P's avatar
Denis_P committed
12
  - publish
Denis_P's avatar
Denis_P committed
13
14
15

variables:
  GIT_STRATEGY:                    fetch
Denis_P's avatar
Denis_P committed
16
  GIT_DEPTH:                       100
17
18
  CARGO_INCREMENTAL:               0
  CARGO_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
19
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
20
  ALL_CRATES:                      "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
Denis_P's avatar
Denis_P committed
21

22
23
24
25
26
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

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

Denis_P's avatar
Denis_P committed
61
62

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

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

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

Denis_P's avatar
Denis_P committed
80

Denis_P's avatar
Denis_P committed
81
82
#### stage:                        workspace

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

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

Denis_P's avatar
Denis_P committed
105
106
test:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
107
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
108
  needs:
109
110
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
111
  script:
112
    - cargo test --verbose --all-features --no-fail-fast --workspace
113
114
115
116
117

codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
118
119
    - job:                         check-std
      artifacts:                   false
120
  variables:
Denis_P's avatar
Denis_P committed
121
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
122
    CARGO_INCREMENTAL:             0
123
124
    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
125
126
127
    # 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.
128
129
130
    # We removed the `-Cinline-threshold=0` flag from the above `RUSTFLAGS` since it was bugged
    # at the time and lead to inlining of functions that shouldn't be inlined for the coverage
    # report. (More information here: https://github.com/Kogia-sima/rust-covfix/issues/2)
131
132
133
134
135
136
  script:
    # RUSTFLAGS are the cause target cache can't be used here
    - unset "CARGO_TARGET_DIR"
    - cargo clean
    - cargo test --verbose --all-features --no-fail-fast --workspace
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
137
138
139
    # 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
140
141
    # 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
142
143
144
145
146
    - 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
147

Hero Bird's avatar
Hero Bird committed
148
clippy-std:
Denis_P's avatar
Denis_P committed
149
  stage:                           workspace
Denis_P's avatar
Denis_P committed
150
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
151
  needs:
152
153
    - job:                         check-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
154
  script:
Hero Bird's avatar
Hero Bird committed
155
    - for crate in ${ALL_CRATES}; do
156
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
157
      done
Denis_P's avatar
Denis_P committed
158

Hero Bird's avatar
Hero Bird committed
159
clippy-wasm:
Denis_P's avatar
Denis_P committed
160
  stage:                           workspace
Denis_P's avatar
Denis_P committed
161
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
162
  needs:
163
164
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
165
  script:
166
    - for crate in ${ALL_CRATES}; do
167
        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
168
169
170
      done

fmt:
Denis_P's avatar
Denis_P committed
171
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
172
173
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
174
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
175

Denis_P's avatar
Denis_P committed
176

Denis_P's avatar
Denis_P committed
177
#### stage:                        examples
Denis_P's avatar
Denis_P committed
178

Denis_P's avatar
Denis_P committed
179
.update-cargo-contract:            &update-cargo-contract
180
181
182
183
  # `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
184
185
  - cargo contract -V

Hero Bird's avatar
Hero Bird committed
186
examples-test:
Denis_P's avatar
Denis_P committed
187
  stage:                           examples
Denis_P's avatar
Denis_P committed
188
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
189
  needs:
190
191
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
192
  script:
193
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
194
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
195
196
      done

Hero Bird's avatar
Hero Bird committed
197
examples-fmt:
Denis_P's avatar
Denis_P committed
198
  stage:                           examples
Denis_P's avatar
Denis_P committed
199
200
  <<:                              *docker-env
  script:
201
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
202
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
203
204
      done

Hero Bird's avatar
Hero Bird committed
205
examples-clippy-std:
Denis_P's avatar
Denis_P committed
206
  stage:                           examples
Denis_P's avatar
Denis_P committed
207
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
208
  needs:
209
210
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
211
  script:
212
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
213
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
214
215
216
217
218
219
      done

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
220
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
221
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
222
223
224
225
226
227
      done

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
Denis_P's avatar
Denis_P committed
228
    - *update-cargo-contract
229
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
230
231
232
233
234
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
235
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
236
237
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
238
  needs:
239
240
    - job:                         build-wasm
      artifacts:                   false
Hero Bird's avatar
Hero Bird committed
241
  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
        pushd $example &&
Denis_P's avatar
Denis_P committed
245
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
246
        popd;
Denis_P's avatar
Denis_P committed
247
      done
Denis_P's avatar
Denis_P committed
248
249
250
251
252
253

#### stage:                        publish

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