---
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

pre-commit:
  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:
  rules:
    - if: '$VERSION != "9.3.6"'
      variables:
        TANGO_WARNINGS_AS_ERRORS: ON
  needs:
    - job: pre-commit
      artifacts: false
  before_script:
    - python3 -m venv venv
    - source venv/bin/activate
    - pip install -r tests/requirements.txt

build-tangoadmin-linux-stock:
  image: debian:bullseye
  tags:
    - docker, linux, amd64
  needs:
    - job: pre-commit
      artifacts: false
  before_script:
    - apt-get update
    - >
      apt-get install -y
      build-essential
      cmake
      git
      libcos4-dev
      libomniorb4-dev
      libomnithread4-dev
      libzmq3-dev
      omniidl
      python3-venv
      pkg-config
    - mkdir build
  script:
    - apt-get install -y libtango-dev
    - cmake -DBUILD_TESTING=OFF -B build .
    - make -j$(nproc) -C build install

windows:build-tangoadmin:
  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
