stages:
  - test
  - build

image:                             parity/rust-builder:latest

variables:
  GIT_STRATEGY:                    fetch
  GIT_SUBMODULE_STRATEGY:          recursive
  CARGO_HOME:                      "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}"
  SCCACHE_DIR:                     "/ci-cache/${CI_PROJECT_NAME}/sccache"
  CI_SERVER_NAME:                  "GitLab CI"
  RUST_TOOLCHAIN:                  "stable"

.docker-env:                       &docker-env
  image:                           parity/rust-builder:latest
  before_script:
    - rustup show
    - cargo --version
    - sccache -s
  retry:
    max: 2
    when: 
      - runner_system_failure
      - unknown_failure
      - api_failure
  tags:
    - linux-docker

#### stage:                        test

test-rust-stable:
  stage:                           test
  <<:                              *docker-env
  script:
    - ./scripts/init.sh
    - time cargo test --all --release --locked
    - cd substrate && time cargo test --all --release --locked
    - sccache -s
  only:
    - triggers
    - tags
    - master
    - schedules
    - web
    - /^[0-9]+$/

#### stage:                        build

build-linux:
  stage:                           build
  <<:                              *docker-env
  script:
    - ./scripts/init.sh
    - time cargo build --release
    - cd substrate && time cargo build --release
    - sccache -s
  only:
    - master
    - tags
    - web
