---
include:
  - project: 'tango-controls/gitlab-ci-templates'
    file: 'ArchiveWithSubmodules.gitlab-ci.yml'
  - project: 'tango-controls/gitlab-ci-templates'
    file: 'cpp.gitlab-ci.yml'

variables:
  DEBIAN_FRONTEND: noninteractive
  GIT_SUBMODULE_STRATEGY: recursive
  TANGO_WARNINGS_AS_ERRORS: ON
  CMAKE_CUSTOM_ARGS: "-DBUILD_TESTING=ON"
  TESTING: ON

# See: https://docs.gitlab.com/ce/ci/yaml/README.html#workflowrules-templates
workflow:
  rules:
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

pre-commit:
  stage: check
  image: registry.gitlab.com/tango-controls/docker/pre-commit:3.7.0-2
  tags:
    - docker, linux, amd64
  variables:
    PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
    PATCH_FILE: clang-format.patch
  script:
    - pre-commit run --all-files --show-diff-on-failure || true
    - git diff > ${PATCH_FILE}
      # fail job if the patch file is not empty
    - '! test -s ${PATCH_FILE}'
  cache:
    key: pre-commit-cache
    paths:
      - ${PRE_COMMIT_HOME}
  artifacts:
    when: always
    paths:
      - ${PATCH_FILE}

build-linux:
  stage: build
  rules:
    - if: '$VERSION == "lts"'
      variables:
        CMAKE_CXX_FLAGS: "-I /home/tango/include -I /home/tango/include/tango"
        TANGO_WARNINGS_AS_ERRORS: OFF
        CMAKE_CUSTOM_ARGS: "-DBUILD_TESTING=OFF"
      when: on_success
    - when: on_success
  needs:
    - job: pre-commit
      artifacts: false

test-linux:
  stage: test
  rules:
    - if: '$VERSION == "lts"'
      when: never
    - when: on_success
  before_script:
    - python3 -m venv venv
    - source venv/bin/activate
    - pip install -r tests/requirements.txt

windows:build-tangoadmin:
  stage: build
  tags:
    - windows
    - desy
  needs:
    - job: pre-commit
      artifacts: false
  before_script:
    - iwr -useb https://pixi.sh/install.ps1 | iex
    - $env:PATH = "C:\windows\system32\config\systemprofile\.pixi\bin;" + $env:PATH
  script:
    - pixi run install
    - pixi run test
  allow_failure: true
