.gitlab-ci.yml 11.9 KB
Newer Older
Denis_P's avatar
Denis_P committed
# .gitlab-ci.yml
#
# ink
#
# pipelines can be triggered manually in the web


stages:
  - check
  - workspace
Denis_P's avatar
Denis_P committed
  - examples
Denis_P's avatar
Denis_P committed

variables:
  GIT_STRATEGY:                    fetch
Denis_P's avatar
Denis_P committed
  GIT_DEPTH:                       100
Denis_P's avatar
Denis_P committed
  CARGO_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
  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

workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

Denis_P's avatar
Denis_P committed
.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
  image:                           paritytech/ink-ci-linux:latest
Denis_P's avatar
Denis_P committed
  before_script:
Denis_P's avatar
Denis_P committed
    - cargo -vV
    - rustc -vV
Denis_P's avatar
Denis_P committed
    - rustup show
Denis_P's avatar
Denis_P committed
    - bash --version
Denis_P's avatar
Denis_P committed
    - ./scripts/pre_cache.sh
Denis_P's avatar
Denis_P committed
    - sccache -s
  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_BRANCH
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1
  interruptible:                   true
  retry:
    max: 2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure
Denis_P's avatar
Denis_P committed
  tags:
    - linux-docker


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

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

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

#### stage:                        workspace

Hero Bird's avatar
Hero Bird committed
build-std:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
Hero Bird's avatar
Hero Bird committed
    - for crate in ${ALL_CRATES}; do
        cargo build --verbose --all-features --release --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
      done
Denis_P's avatar
Denis_P committed

Hero Bird's avatar
Hero Bird committed
build-wasm:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
    - for crate in ${ALSO_WASM_CRATES}; do
        cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path crates/${crate}/Cargo.toml;
Hero Bird's avatar
Hero Bird committed
      done
Denis_P's avatar
Denis_P committed

test:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
  variables:
      # Since we run the tests with `--all-features` this implies the feature
      # `ink-fuzz-tests` as well -- i.e. the fuzz tests are run.
      # There's no way to disable a single feature while enabling all features
      # at the same time, hence we use this workaround.
      QUICKCHECK_TESTS:            0
Denis_P's avatar
Denis_P committed
  script:
    - cargo test --verbose --all-features --no-fail-fast --workspace

codecov:
  stage:                           workspace
  <<:                              *docker-env
  needs:
    # For codecov it's sufficient to run the fuzz tests only once.
    QUICKCHECK_TESTS:              1
Denis_P's avatar
Denis_P committed
    # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
    CARGO_INCREMENTAL:             0
    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
    # 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
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
    - unset "CARGO_TARGET_DIR"
Denis_P's avatar
Denis_P committed
    - unset "CARGO_HOME"
Denis_P's avatar
Denis_P committed
  script:
    # RUSTFLAGS are the cause target cache can't be used here
    - cargo build --verbose --all-features --workspace
Denis_P's avatar
Denis_P committed
    - cargo test --verbose --all-features --no-fail-fast --workspace
Denis_P's avatar
Denis_P committed
    # 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
    # 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
    - 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

Hero Bird's avatar
Hero Bird committed
clippy-std:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
Hero Bird's avatar
Hero Bird committed
    - for crate in ${ALL_CRATES}; do
        cargo clippy --verbose --all-features --manifest-path crates/${crate}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
      done
Denis_P's avatar
Denis_P committed

Hero Bird's avatar
Hero Bird committed
clippy-wasm:
  stage:                           workspace
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
    - for crate in ${ALSO_WASM_CRATES}; do
        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
      done

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

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

.update-cargo-contract:            &update-cargo-contract
  # `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 $?
  - cargo contract -V

Hero Bird's avatar
Hero Bird committed
examples-test:
Denis_P's avatar
Denis_P committed
  stage:                           examples
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
    - for example in examples/*/; do
        cargo test --verbose --manifest-path ${example}/Cargo.toml;
Denis_P's avatar
Denis_P committed
      done

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

Hero Bird's avatar
Hero Bird committed
examples-clippy-std:
Denis_P's avatar
Denis_P committed
  stage:                           examples
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  needs:
Denis_P's avatar
Denis_P committed
  script:
    - for example in examples/*/; do
Denis_P's avatar
Denis_P committed
        cargo clippy --verbose --manifest-path ${example}/Cargo.toml -- -D warnings;
Hero Bird's avatar
Hero Bird committed
      done

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

examples-contract-build:
  stage:                           examples
  <<:                              *docker-env
  script:
    - *update-cargo-contract
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
        pushd $example &&
        cargo contract build &&
        popd;
      done

examples-generate-metadata:
Hero Bird's avatar
Hero Bird committed
  stage:                           examples
  <<:                              *docker-env
  needs:
Hero Bird's avatar
Hero Bird committed
  script:
    - *update-cargo-contract
    - for example in examples/*/; do
Hero Bird's avatar
Hero Bird committed
        pushd $example &&
        cargo contract generate-metadata &&
Hero Bird's avatar
Hero Bird committed
        popd;
Denis_P's avatar
Denis_P committed
      done
Denis_P's avatar
Denis_P committed

#### stage:                        publish

publish-docs:
  stage:                           publish
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
  variables:
    GIT_DEPTH:                     0
  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
  script:
Denis_P's avatar
Denis_P committed
    - rm -rf /tmp/*
    - unset CARGO_TARGET_DIR
Denis_P's avatar
Denis_P committed
    # 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
    - git config remote.origin.url "https://${GITHUB_TOKEN}@github.com/paritytech/ink.git"
Denis_P's avatar
Denis_P committed
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
Denis_P's avatar
Denis_P committed
    # Generating Docs
Denis_P's avatar
Denis_P committed
    - time cargo doc --no-deps --all-features
        -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
    # saving README and docs
    - mv target/doc/ /tmp/
    - cp README.md /tmp/doc/
Denis_P's avatar
Denis_P committed
    - git checkout gh-pages
Denis_P's avatar
Denis_P committed
    - mv _config.yml /tmp/doc/
    # remove everything and restore generated docs, README and Jekyll config
Denis_P's avatar
Denis_P committed
    - rm -rf ./*
Denis_P's avatar
Denis_P committed
    - mv /tmp/doc/* .
Denis_P's avatar
Denis_P committed
    # Upload files
Denis_P's avatar
Denis_P committed
    - git add --all --force
Denis_P's avatar
Denis_P committed
    - git status
Denis_P's avatar
Denis_P committed
    - git commit -m "Updated docs for ${CI_COMMIT_REF_NAME} and pushed to gh-pages"
Denis_P's avatar
Denis_P committed
    - git push origin gh-pages --force
Denis_P's avatar
Denis_P committed
  after_script:
    - rm -rf .git/ ./*

#### stage:                        fuzz

fuzz-tests:
    stage:                           fuzz
    <<:                              *docker-env
    variables:
        # The QUICKCHECK_TESTS default is 100
        QUICKCHECK_TESTS:            50000
    rules:
        - if: $CI_PIPELINE_SOURCE == "schedule"
        - if: $CI_COMMIT_REF_NAME == "master"
    script:
        # We fuzz-test only crates which possess the `ink-fuzz-tests` feature
        - all_tests_passed=0
        - for crate in ${ALL_CRATES}; do
            if grep "ink-fuzz-tests =" crates/${crate}/Cargo.toml;
            then
                cargo test --verbose --features ink-fuzz-tests --manifest-path crates/${crate}/Cargo.toml --no-fail-fast -- fuzz_;
                let "all_tests_passed |= $?";
            fi
          done
        - if [ $all_tests_passed -eq 0 ]; then exit 0; fi
        - |
             curl -X "POST" "https://api.github.com/repos/paritytech/ink/issues?state=all" \
                -H "Cookie: logged_in=no" \
                -H "Authorization: token ${GITHUB_TOKEN}" \
                -H "Content-Type: text/plain; charset=utf-8" \
                -d $'{
                    "title": "[ci] Failing fuzz tests on master ('"$( date +"%d %b %Y" )"'),
                    "body": "This CI job '"${CI_JOB_ID}"' just failed: '"${CI_JOB_URL}"'.\n\nThe offending commit is `['"${CI_COMMIT_TITLE}"'](https://github.com/paritytech/ink/commit/'"${CI_COMMIT_SHA}"')`.",
                    "assignees": [],
                    "labels": [
                        "P-high"
                    ]
                }'