.gitlab-ci.yml 3.27 KiB
Newer Older
# .gitlab-ci.yml
#
# cargo-contract
#
# pipelines can be triggered manually in the web


stages:
  - check
  - test
  - build

variables:
  GIT_STRATEGY:                    fetch
Denis_P's avatar
Denis_P committed
  GIT_DEPTH:                       "100"
  CARGO_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
Denis_P's avatar
Denis_P committed
  RUST_LIB_BACKTRACE:              "0"

Michael Müller's avatar
Michael Müller committed
# Necessary for building binaryen-sys, which is part of the binaryen dependency.
# Should be reverted once the `cargo-contract` ci image provides a clang version
# for which building `binaryen-sys` works (paritytech/scripts/#237).
  CXX:                             "/usr/bin/clang++-8"

Denis_P's avatar
Denis_P committed
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

.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
  image:                           paritytech/contracts-ci-linux:latest
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
Denis_P's avatar
Denis_P committed
    - ./scripts/pre_cache.sh
    # global RUSTFLAGS overrides the linker args so this way is better to pass the flags
Denis_P's avatar
Denis_P committed
    - printf '[build]\nrustflags = ["-C", "link-dead-code"]\n' > ${CARGO_HOME}/config
    - sccache -s
Denis_P's avatar
Denis_P committed
  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 =~ /^[0-9]+$/                   # PRs
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1
  dependencies:                    []
  interruptible:                   true
  retry:
Denis_P's avatar
Denis_P committed
    max:                           2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure
  tags:
    - linux-docker


#### stage:                        check
# be aware that the used image has cargo-contract installed

fmt:
  stage:                           check
  <<:                              *docker-env
  script:
    - cargo fmt --verbose --all -- --check

#### stage:                        test (all features)

test:
  stage:                           test
  <<:                              *docker-env
  script:
    # We are temporarily removing `--all-features` here for the build to succeed
    # until our substrate dependencies are released in newer versions.
    - cargo test --verbose --workspace
#### stage:                        build (default features)
build:
  stage:                           build
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_COMMIT_REF_NAME == "master"
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1
    - cargo build --verbose --release
Denis_P's avatar
Denis_P committed
  after_script:
    - mkdir -p ./artifacts/cargo-contract/
    - cp ${CARGO_TARGET_DIR}/release/cargo-contract ./artifacts/cargo-contract/