default:
  # Official language image. Look for the different tagged releases at:
  # https://hub.docker.com/r/library/rust/tags/
  image: "rust:latest"

# Optional: Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: https://docs.gitlab.com/ee/ci/services/index.html
# services:
#   - mysql:latest
#   - redis:latest
#   - postgres:latest

# Optional: Install a C compiler, cmake and git into the container.
# You will often need this when you (or any of your dependencies) depends on C code.
#before_script:
#  - apt-get update -yqq
#  - apt-get install -yqq --no-install-recommends build-essential

stages:
  - test
  - build
  - deploy

# Build the main application (currently mostly useless)
build-main:
  stage: build
  tags:
    - opossum
  script:
    - export HTTPS_PROXY=lxproxy01.gsi.de:3128
    - export HTTP_PROXY=lxproxy01.gsi.de:3128
    - export https_proxy=lxproxy01.gsi.de:3128
    - export http_proxy=lxproxy01.gsi.de:3128
    - cargo build
  dependencies:
    - test:cargo

# Build API documentation
build-doc:
  stage: build
  tags:
    - opossum
  script:
    - export HTTPS_PROXY=lxproxy01.gsi.de:3128
    - export HTTP_PROXY=lxproxy01.gsi.de:3128
    - export https_proxy=lxproxy01.gsi.de:3128
    - export http_proxy=lxproxy01.gsi.de:3128
    - cargo doc --no-deps
  dependencies:
    - test:cargo
# Use cargo to test the project
test:cargo:
  stage: test
  tags:
    - opossum
  script:
    - export HTTPS_PROXY=lxproxy01.gsi.de:3128
    - export HTTP_PROXY=lxproxy01.gsi.de:3128
    - export https_proxy=lxproxy01.gsi.de:3128
    - export http_proxy=lxproxy01.gsi.de:3128
    - rustup default nightly
    - cargo install junitify
    - rustc --version && cargo --version # Print version info for debugging
    # - cargo test --workspace
    - cargo test -- --format=json -Z unstable-options --report-time | junitify --out $CI_PROJECT_DIR/tests/
  artifacts:
    when: always
    reports:
      junit: $CI_PROJECT_DIR/tests/*.xml

test:clippy:
  stage: test
  tags:
    - opossum
  script:
    - export HTTPS_PROXY=lxproxy01.gsi.de:3128
    - export HTTP_PROXY=lxproxy01.gsi.de:3128
    - export https_proxy=lxproxy01.gsi.de:3128
    - export http_proxy=lxproxy01.gsi.de:3128
    - rustup component add clippy
    - cargo clippy --workspace
  allow_failure: true
  dependencies:
    - test:cargo
test:clippy_windows:
  stage: test
  tags:
    - windows
  script:
    - set CARGO_HOME=C:\Users\ueisenb\AppData\Local\0_gsi_executables\.cargo
    - set CARGO_TARGET_DIR=C:\Users\ueisenb\Appdata\Local\0_gsi_executables\gitlab-runner\target
    - set PATH=%PATH%;C:\Users\ueisenb\AppData\Local\0_gsi_executables\.cargo\bin
    - cargo clippy --workspace

#deploy:
#  stage: deploy
#  script: echo "Define your deployment script!"
#  environment: production
