.gitlab-ci.yml 8.81 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
Denis_P's avatar
Denis_P committed
17
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
18
  CI_SERVER_NAME:                  "GitLab CI"
19
  REGISTRY:                        "paritytech"
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
Denis_P's avatar
Denis_P committed
31
  image:                           ${REGISTRY}/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
39
40
41
42
43
    - sccache -s
  only:
    - master
    - /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1
    - schedules
    - web
Denis_P's avatar
Denis_P committed
44
    - branches
Denis_P's avatar
Denis_P committed
45
46
  dependencies:                    []
  interruptible:                   true
47
48
  retry:
    max: 2
Denis_P's avatar
Denis_P committed
49
    when:
50
51
52
      - runner_system_failure
      - unknown_failure
      - api_failure
Denis_P's avatar
Denis_P committed
53
54
55
  tags:
    - linux-docker

Denis_P's avatar
Denis_P committed
56
57

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

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

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

Denis_P's avatar
Denis_P committed
75

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

Hero Bird's avatar
Hero Bird committed
78
build-std:
Denis_P's avatar
Denis_P committed
79
  stage:                           workspace
Denis_P's avatar
Denis_P committed
80
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
81
  needs:
Denis_P's avatar
Denis_P committed
82
    - check-std
Denis_P's avatar
Denis_P committed
83
  script:
Hero Bird's avatar
Hero Bird committed
84
    - for crate in ${ALL_CRATES}; do
Hero Bird's avatar
Hero Bird committed
85
        cargo build --verbose --all-features --release --manifest-path ${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:
Denis_P's avatar
Denis_P committed
92
    - check-wasm
Denis_P's avatar
Denis_P committed
93
  script:
94
    - for crate in ${ALL_CRATES}; do
Hero Bird's avatar
Hero Bird committed
95
96
        cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path ${crate}/Cargo.toml;
      done
Denis_P's avatar
Denis_P committed
97

Denis_P's avatar
Denis_P committed
98
99
test:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
100
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
101
  needs:
Denis_P's avatar
Denis_P committed
102
    - check-std
Denis_P's avatar
Denis_P committed
103
  script:
104
    - cargo test --verbose --all-features --no-fail-fast --workspace
105
106
107
108
109
110
111

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

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

Hero Bird's avatar
Hero Bird committed
149
clippy-wasm:
Denis_P's avatar
Denis_P committed
150
  stage:                           workspace
Denis_P's avatar
Denis_P committed
151
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
152
  needs:
Denis_P's avatar
Denis_P committed
153
    - check-wasm
Denis_P's avatar
Denis_P committed
154
  script:
155
    - for crate in ${ALL_CRATES}; do
Denis_P's avatar
Denis_P committed
156
        cargo clippy --verbose --no-default-features --manifest-path ${crate}/Cargo.toml --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
157
158
159
      done

fmt:
Denis_P's avatar
Denis_P committed
160
  stage:                           workspace
Hero Bird's avatar
Hero Bird committed
161
162
  <<:                              *docker-env
  script:
Hero Bird's avatar
Hero Bird committed
163
    - cargo fmt --verbose --all -- --check
Hero Bird's avatar
Hero Bird committed
164

Denis_P's avatar
Denis_P committed
165

Denis_P's avatar
Denis_P committed
166
#### stage:                        examples
Denis_P's avatar
Denis_P committed
167

Denis_P's avatar
Denis_P committed
168
.update-cargo-contract:            &update-cargo-contract
169
170
171
172
  # `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
173
174
  - cargo contract -V

Hero Bird's avatar
Hero Bird committed
175
examples-test:
Denis_P's avatar
Denis_P committed
176
  stage:                           examples
Denis_P's avatar
Denis_P committed
177
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
178
179
  needs:
    - clippy-std
Denis_P's avatar
Denis_P committed
180
  script:
181
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
182
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
183
184
      done

Hero Bird's avatar
Hero Bird committed
185
examples-fmt:
Denis_P's avatar
Denis_P committed
186
  stage:                           examples
Denis_P's avatar
Denis_P committed
187
188
  <<:                              *docker-env
  script:
189
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
190
        cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
Denis_P's avatar
Denis_P committed
191
192
      done

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

examples-clippy-wasm:
  stage:                           examples
  <<:                              *docker-env
  script:
207
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
208
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features --target wasm32-unknown-unknown -- -D warnings;
Hero Bird's avatar
Hero Bird committed
209
210
211
212
213
214
      done

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
Denis_P's avatar
Denis_P committed
215
    - *update-cargo-contract
216
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
217
218
219
220
221
        pushd $example &&
        cargo contract build &&
        popd;
      done

Denis_P's avatar
Denis_P committed
222
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
223
224
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
225
226
  needs:
    - build-wasm
Hero Bird's avatar
Hero Bird committed
227
  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
        pushd $example &&
Denis_P's avatar
Denis_P committed
231
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
232
        popd;
Denis_P's avatar
Denis_P committed
233
      done
Denis_P's avatar
Denis_P committed
234
235
236
237
238
239

#### stage:                        publish

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