.gitlab-ci.yml 9.72 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:                      "core core/derive alloc prelude primitives lang lang/macro lang/ir"
Denis_P's avatar
Denis_P committed
21
22
23
24
25
26
27
28
29
30

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

Denis_P's avatar
Denis_P committed
55
56

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

Hero Bird's avatar
Hero Bird committed
58
check-std:
Denis_P's avatar
Denis_P committed
59
  stage:                           check
Denis_P's avatar
Denis_P committed
60
61
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
62
    - for crate in ${ALL_CRATES}; do
63
        cargo check --verbose --all-features --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
64
      done
Denis_P's avatar
Denis_P committed
65

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

Denis_P's avatar
Denis_P committed
74

Denis_P's avatar
Denis_P committed
75
76
#### stage:                        workspace

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

Hero Bird's avatar
Hero Bird committed
88
build-wasm:
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-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
94
  script:
95
    - for crate in ${ALL_CRATES}; do
96
        cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
97
      done
Denis_P's avatar
Denis_P committed
98

Denis_P's avatar
Denis_P committed
99
100
test:
  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-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
105
  script:
106
    - cargo test --verbose --all-features --no-fail-fast --workspace
107
108
109
110
111

codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
112
113
    - job:                         check-std
      artifacts:                   false
114
  variables:
Denis_P's avatar
Denis_P committed
115
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
116
    CARGO_INCREMENTAL:             0
117
118
    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
119
120
121
    # 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.
122
123
124
    # 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)
125
126
127
128
129
130
  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
131
132
133
    # 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
134
135
    # 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
136
137
138
139
140
    - 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
141

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

Hero Bird's avatar
Hero Bird committed
153
clippy-wasm:
Denis_P's avatar
Denis_P committed
154
  stage:                           workspace
Denis_P's avatar
Denis_P committed
155
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
156
  needs:
157
158
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
159
  script:
160
    - for crate in ${ALL_CRATES}; do
161
        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
162
163
164
      done

fmt:
Denis_P's avatar
Denis_P committed
165
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
166
167
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
168
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
169

Denis_P's avatar
Denis_P committed
170

Denis_P's avatar
Denis_P committed
171
#### stage:                        examples
Denis_P's avatar
Denis_P committed
172

Denis_P's avatar
Denis_P committed
173
.update-cargo-contract:            &update-cargo-contract
174
175
176
177
  # `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
178
179
  - cargo contract -V

Hero Bird's avatar
Hero Bird committed
180
examples-test:
Denis_P's avatar
Denis_P committed
181
  stage:                           examples
Denis_P's avatar
Denis_P committed
182
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
183
  needs:
184
185
    - job:                         clippy-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
186
  script:
187
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
188
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
189
190
      done

Hero Bird's avatar
Hero Bird committed
191
examples-fmt:
Denis_P's avatar
Denis_P committed
192
  stage:                           examples
Denis_P's avatar
Denis_P committed
193
194
  <<:                              *docker-env
  script:
195
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
196
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
197
198
      done

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

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
214
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
215
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
216
217
218
219
220
221
      done

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
Denis_P's avatar
Denis_P committed
222
    - *update-cargo-contract
223
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
224
225
226
227
228
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
229
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
230
231
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
232
  needs:
233
234
    - job:                         build-wasm
      artifacts:                   false
Hero Bird's avatar
Hero Bird committed
235
  script:
Denis_P's avatar
Denis_P committed
236
    - *update-cargo-contract
237
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
238
        pushd $example &&
Denis_P's avatar
Denis_P committed
239
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
240
        popd;
Denis_P's avatar
Denis_P committed
241
      done
Denis_P's avatar
Denis_P committed
242
243
244
245
246
247

#### stage:                        publish

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