.gitlab-ci.yml 8.64 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"
Denis_P's avatar
Denis_P committed
19
  REGISTRY:                        registry.parity.io/parity/infrastructure/scripts
20
  ALL_CRATES:                      "core alloc prelude primitives lang lang/macro"
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 169
.update-cargo-contract:            &update-cargo-contract
  # `cargo install` returns an error if there is nothing to update, so have to supress it here temporarily
170
  - cargo install cargo-contract || echo $?
Denis_P's avatar
Denis_P committed
171 172
  - cargo contract -V

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

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

Hero Bird's avatar
Hero Bird committed
191
examples-clippy-std:
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 195
  needs:
    - clippy-std
Denis_P's avatar
Denis_P committed
196
  script:
197
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
198
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
199 200 201 202 203 204
      done

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

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

Denis_P's avatar
Denis_P committed
220
examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
221 222
  stage:                           examples
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
223 224
  needs:
    - build-wasm
Hero Bird's avatar
Hero Bird committed
225
  script:
Denis_P's avatar
Denis_P committed
226
    - *update-cargo-contract
227
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
228
        pushd $example &&
Denis_P's avatar
Denis_P committed
229
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
230
        popd;
Denis_P's avatar
Denis_P committed
231
      done
Denis_P's avatar
Denis_P committed
232 233 234 235 236 237

#### stage:                        publish

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