.gitlab-ci.yml 9.91 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
  CARGO_INCREMENTAL:               0
Denis_P's avatar
Denis_P committed
18
  CARGO_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_COMMIT_REF_NAME}/${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
21
22
  PURELY_STD_CRATES:               "lang/codegen metadata"
  ALSO_WASM_CRATES:                "env storage storage/derive allocator prelude primitives lang lang/macro lang/ir"
  ALL_CRATES:                      "${PURELY_STD_CRATES $ALSO_WASM_CRATES}"
Denis_P's avatar
Denis_P committed
23

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

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

Denis_P's avatar
Denis_P committed
63
64

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

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

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

Denis_P's avatar
Denis_P committed
82

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

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

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

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

codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
120
121
    - job:                         check-std
      artifacts:                   false
122
  variables:
Denis_P's avatar
Denis_P committed
123
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
124
    CARGO_INCREMENTAL:             0
125
126
    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
127
128
129
    # 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
130
131
132
133
134
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
135
    - unset "CARGO_TARGET_DIR"
Denis_P's avatar
Denis_P committed
136
    - unset "CARGO_HOME"
137
    - cargo clean
Denis_P's avatar
Denis_P committed
138
139
  script:
    # RUSTFLAGS are the cause target cache can't be used here
140
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
141
    - cargo test --verbose --all-features --no-fail-fast --workspace
Denis_P's avatar
Denis_P committed
142
143
144
    # 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
145
146
    # 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
147
148
149
150
151
    - 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
152

Hero Bird's avatar
Hero Bird committed
153
clippy-std:
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-std
      artifacts:                   false
Denis_P's avatar
Denis_P committed
159
  script:
Hero Bird's avatar
Hero Bird committed
160
    - for crate in ${ALL_CRATES}; do
161
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
162
      done
Denis_P's avatar
Denis_P committed
163

Hero Bird's avatar
Hero Bird committed
164
clippy-wasm:
Denis_P's avatar
Denis_P committed
165
  stage:                           workspace
Denis_P's avatar
Denis_P committed
166
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
167
  needs:
168
169
    - job:                         check-wasm
      artifacts:                   false
Denis_P's avatar
Denis_P committed
170
  script:
171
    - for crate in ${ALSO_WASM_CRATES}; do
172
        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
173
174
175
      done

fmt:
Denis_P's avatar
Denis_P committed
176
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
177
178
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
179
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
180

Denis_P's avatar
Denis_P committed
181

Denis_P's avatar
Denis_P committed
182
#### stage:                        examples
Denis_P's avatar
Denis_P committed
183

Denis_P's avatar
Denis_P committed
184
.update-cargo-contract:            &update-cargo-contract
185
186
187
188
  # `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
189
190
  - cargo contract -V

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

Hero Bird's avatar
Hero Bird committed
202
examples-fmt:
Denis_P's avatar
Denis_P committed
203
  stage:                           examples
Denis_P's avatar
Denis_P committed
204
205
  <<:                              *docker-env
  script:
206
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
207
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
208
209
      done

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

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

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
Denis_P's avatar
Denis_P committed
233
    - *update-cargo-contract
234
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
235
236
237
238
239
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
240
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
241
242
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
243
  needs:
244
245
    - job:                         build-wasm
      artifacts:                   false
Hero Bird's avatar
Hero Bird committed
246
  script:
Denis_P's avatar
Denis_P committed
247
    - *update-cargo-contract
248
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
249
        pushd $example &&
Denis_P's avatar
Denis_P committed
250
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
251
        popd;
Denis_P's avatar
Denis_P committed
252
      done
Denis_P's avatar
Denis_P committed
253
254
255
256
257
258

#### stage:                        publish

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