# .gitlab-ci.yml
#

stages:
  - check
  - test
  - build

variables:
  GIT_STRATEGY:                    fetch
  GIT_DEPTH:                       "100"
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
  CARGO_INCREMENTAL:               0
  CI_SERVER_NAME:                  "GitLab CI"

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

.docker-env:                       &docker-env
  image:                           tetcoin/ink-ci-linux:production
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
    - ./scripts/pre_cache.sh
    - sccache -s
  rules:
    - if: $CI_PIPELINE_SOURCE == "trigger"
    - 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_REF_NAME =~ /^[0-9]+$/                         # PRs
    - 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
  tags:
    - linux-docker

#### stage:                        check

check-rust-stable-no_derive_no_std_full:
  stage:                           check
  <<:                              *docker-env
  script:
    - time cargo +stable check --verbose --no-default-features --features bit-vec,generic-array,full
    - sccache -s

check-rust-stable-no_derive_no_std:
  stage:                           check
  <<:                              *docker-env
  script:
    - time cargo +stable check --verbose --no-default-features --features bit-vec,generic-array
    - sccache -s

check-rust-stable-no_std-chain-error:
  stage:                           check
  <<:                              *docker-env
  script:
    - time cargo +stable check --verbose --no-default-features --features chain-error
    - sccache -s

check-rust-stable-no_derive_full:
  stage:                           check
  <<:                              *docker-env
  script:
    - time cargo +stable check --verbose --features bit-vec,generic-array,full
    - sccache -s

#### stage:                        test

test-rust-stable:
  stage:                           test
  <<:                              *docker-env
  script:
    - time cargo +stable test --verbose --all --features bit-vec,generic-array,derive
    - sccache -s

test-rust-stable-no_derive:
  stage:                           test
  <<:                              *docker-env
  script:
    - time cargo +stable test --verbose --features bit-vec,generic-array
    - sccache -s

bench-rust-nightly:
  stage:                           test
  <<:                              *docker-env
  script:
    - time cargo +nightly bench --features bit-vec,generic-array,derive
    - sccache -s

miri:
  stage:                           test
  <<:                              *docker-env
  variables:
    RUST_BACKTRACE:                1
    MIRIFLAGS:                     "-Zmiri-disable-isolation"
  script:
    - time cargo +nightly miri test --features bit-vec,generic-array,arbitrary --release

#### stage:                        build

build-linux-ubuntu-amd64:
  stage:                           build
  <<:                              *docker-env
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_COMMIT_REF_NAME == "master"
    - if: $CI_COMMIT_REF_NAME == "tags"
  script:
    - cargo build --verbose --release --features bit-vec,generic-array,derive
    - sccache -s
