<% if ci_deploy %>
# Required CI/CD variables:
#   AQUAPI_URL      - devpi index URL for wheel uploads
#   AQUAPI_USERNAME - devpi username for wheel uploads
#   AQUAPI_PASSWORD - devpi password for wheel uploads
#
<% endif %>
# Generated by xmsconan_ci — do not edit manually.

stages:
  - Test
  - Package
<% if ci_deploy %>
  - Deploy
<% endif %>
<% if ci_coverage %>
  - Coverage
  - Pages
<% endif %>

<% if ci_deploy %>
variables:
  DEFAULT_VERSION: "0.0.0"
  PACKAGE_VERSION: "${CI_COMMIT_TAG:-$DEFAULT_VERSION}"

<% endif %>
Conan Build:
  stage: Test
<% if docker_image %>
  image: << docker_image >>
<% elif ci_xvfb %>
  image: docker.aquaveo.com/aquaveo/conan-docker/conan-gcc13-x11-gdal-py3.13
<% else %>
  image: docker.aquaveo.com/aquaveo/conan-docker/conan-gcc13-py3.13
<% endif %>
  artifacts:
    expire_in: '1d'
    when: always
    paths:
<% if ci_deploy %>
      - .export
<% endif %>
      - wheelhouse/
      - test_artifacts/
  script:
    - gcc --version
    - cmake --version
    - python --version
    - pip install conan xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_conan_setup
    - export PACKAGE_VERSION=${CI_COMMIT_TAG:-0.0.0}
    - xmsconan_gen --version ${PACKAGE_VERSION} build.toml
<% if ci_xvfb %>
    - xvfb-run -a -s "-screen 0 1280x1024x24" python build.py --version ${PACKAGE_VERSION} --wheel-dir wheelhouse --artifacts-dir test_artifacts
<% else %>
    - python build.py --version ${PACKAGE_VERSION} --wheel-dir wheelhouse --artifacts-dir test_artifacts
<% endif %>
<% if ci_deploy %>
    - xmsconan_conan_deploy << library_name >> ${PACKAGE_VERSION} --save .export/<< library_name >>-linux-${PACKAGE_VERSION}.tar.gz
<% endif %>

<% if ci_windows %>
"Conan Build - Windows":
  stage: Test
  image: GLR-py313
  variables:
    AQUAPI_URL: "https://aquapi.aquaveo.com/aquaveo/dev"
  artifacts:
    expire_in: '1d'
    when: always
    paths:
      - .export
      - test_artifacts/
  script:
    - export PACKAGE_VERSION=${CI_COMMIT_TAG:-0.0.0}
    - echo ${PACKAGE_VERSION}
    - python --version
    - pip install conan toml packaging devpi-client
    - python -m pip install xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_conan_setup
    - xmsconan_gen --version ${PACKAGE_VERSION} build.toml
    - python build.py --version ${PACKAGE_VERSION} --artifacts-dir test_artifacts
    - xmsconan_conan_deploy << library_name >> ${PACKAGE_VERSION} --save .export/<< library_name >>-windows-${PACKAGE_VERSION}.tar.gz
  tags:
    - WinVM

<% endif %>
Lint:
  stage: Test
  image: python:3.13
  allow_failure: true
  script:
    - pip install flake8 flake8-docstrings flake8-bugbear flake8-import-order pep8-naming flake8-colors flake8-tidy-imports
    - pip install -i https://aquapi.aquaveo.com/aquaveo/dev/+simple/ flake8-aquaveo
    - pip install xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_gen --version 0.0.0 build.toml
    - flake8 _package

Repair Wheel:
  stage: Package
<% if docker_image %>
  image: << docker_image >>
<% elif ci_xvfb %>
  image: docker.aquaveo.com/aquaveo/conan-docker/conan-gcc13-x11-gdal-py3.13
<% else %>
  image: quay.io/pypa/manylinux_2_28_x86_64
<% endif %>
  dependencies:
    - Conan Build
  script:
    - /opt/python/cp313-cp313/bin/pip install xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - /opt/python/cp313-cp313/bin/xmsconan_wheel_repair --wheel-dir wheelhouse
  artifacts:
    expire_in: '1d'
    paths:
      - wheelhouse/

<% if ci_deploy %>
"Wheel Deploy":
  stage: Deploy
  image: python:3.13
  dependencies:
    - Repair Wheel
  script:
    - pip install xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_wheel_deploy --wheel-dir wheelhouse
  only:
    - tags

"Conan Deploy - Linux":
  stage: Deploy
  image: ubuntu:latest
  dependencies:
    - Conan Build
  script:
    - apt-get update
    - apt-get install -y python3-pip python3-venv
    - python3 -m venv .venv
    - source .venv/bin/activate
    - pip install conan xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_conan_setup
    - export PACKAGE_VERSION=${CI_COMMIT_TAG:-0.0.0}
    - xmsconan_conan_deploy << library_name >> ${PACKAGE_VERSION} --restore .export/<< library_name >>-linux-${PACKAGE_VERSION}.tar.gz --upload
  only:
    - tags

<% if ci_windows %>
"Conan Deploy - Windows":
  stage: Deploy
  image: GLR-py313
  dependencies:
    - "Conan Build - Windows"
  artifacts:
    expire_in: '1d'
    paths:
      - conan_packages/
  script:
    - export PACKAGE_VERSION=${CI_COMMIT_TAG:-0.0.0}
    - pip install conan xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_conan_setup
    - xmsconan_conan_deploy << library_name >> ${PACKAGE_VERSION} --restore .export/<< library_name >>-windows-${PACKAGE_VERSION}.tar.gz --upload
    - mkdir -p conan_packages
    - cp -r /c/Users/admin/.conan2/p/* conan_packages/ || true
  only:
    - tags
  tags:
    - WinVM
<% endif %>
<% endif %>

<% if ci_coverage %>
Coverage:
  stage: Coverage
<% if docker_image %>
  image: << docker_image >>
<% elif ci_xvfb %>
  image: docker.aquaveo.com/aquaveo/conan-docker/conan-gcc13-x11-gdal-py3.13
<% else %>
  image: docker.aquaveo.com/aquaveo/conan-docker/conan-gcc13-py3.13
<% endif %>
  script:
    - pip install lxml conan xmsconan>=<< xmsconan_version >> -i https://public.aquapi.aquaveo.com/aquaveo/dev/+simple
    - xmsconan_conan_setup
    - xmsconan_gen --version 0.0.0 build.toml
    - conan install -pr conan_profiles/linux_testing_debug_coverage.txt . -c tools.cmake.cmake_layout:build_folder_vars="['self.name', 'const.coverage']" --build=missing
    - cmake --preset coverage
    - cmake --build --preset coverage-debug
<% if ci_xvfb %>
    - xvfb-run -a -s "-screen 0 1280x1024x24" ./build/<< library_name >>-coverage/Debug/runner || true
<% else %>
    - ./build/<< library_name >>-coverage/Debug/runner || true
<% endif %>
    - gcovr --root . --object-directory build/<< library_name >>-coverage/Debug --txt --xml coverage.xml --html coverage.html --exclude '.*test_files.*' --exclude '.*\.t\.h$' --exclude '.*\.conan2.*' --exclude '.*/CMakeFiles/.*' --exclude '.*build/.*' --gcov-ignore-errors=no_working_dir_found --gcov-ignore-errors=source_not_found
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml
    paths:
      - coverage.html
      - coverage.xml
  coverage: '/TOTAL.*\s+(\d+%)/'

pages:
  stage: Pages
  dependencies:
    - Coverage
  script:
    - mkdir -p public
    - cp coverage.html public/index.html
  artifacts:
    paths:
      - public
  only:
    - master
    - main
<% endif %>
