stages:
 - test
 - deploy

before_script:
  - apt-get update --yes
  - apt-get install --yes build-essential cmake graphviz python3-pyqt5 xvfb xdg-utils lcov
  - python -m pip install --upgrade pip
  - python --version
  - pip install -r requirements.txt
  - pip install $QT_API
  - git fetch --tags
  # - export CXXFLAGS='--coverage'
  # Install without dependencies to make sure that requirements.txt is up-to-date
  - pip install --no-deps -ve .
  # Move file, but should be handled by installation
  - mv _b_asic* b_asic
  - pip show b_asic
  - export QT_API=$QT_API
  # Install test dependencies
  - pip install -r requirements_test.txt
  - export PYTEST_QT_API=$QT_API

.run-test:
  stage: test
  script:
    - pytest --cov=b_asic --cov-report=xml:cov.xml --cov-report=term --color=yes test --mpl --timeout=20 --durations=10
    # - lcov --capture --directory . --output-file coverage.info
    # - lcov --output-file coverage.info --extract coverage.info $PWD/src/'*' $PWD/b_asic/'*'
    # - lcov --list coverage.info
    # - find . -name '*.gc*' -delete
  artifacts:
      reports:
        coverage_report:
          coverage_format: cobertura
          path: cov.xml
  coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/


run-test-3.8-pyside2:
  variables:
    QT_API: pyside2
  image: python:3.8
  extends: ".run-test"

run-test-3.8-pyqt5:
  variables:
    QT_API: pyqt5
  image: python:3.8
  extends: ".run-test"

run-test-3.9-pyside2:
  variables:
    QT_API: pyside2
  image: python:3.9
  extends: ".run-test"

run-test-3.9-pyqt5:
  variables:
    QT_API: pyqt5
  image: python:3.9
  extends: ".run-test"

run-test-3.10-pyside2:
  variables:
    QT_API: pyside2
  image: python:3.10
  extends: ".run-test"

run-test-3.10-pyqt5:
  variables:
    QT_API: pyqt5
  image: python:3.10
  extends: ".run-test"

# PySide2 does not seem to have support for 3.11, "almost works" though
#run-test-3.11-pyside2:
#  variables:
#    QT_API: pyside2
#  image: python:3.11
#  extends: ".run-test"
#  allow_failure: true

run-test-3.11-pyqt5:
  variables:
    QT_API: pyqt5
  image: python:3.11
  extends: ".run-test"

# Seemingly works with Qt6, but tests stall on closing scheduler GUI due to modal dialog(?)
#run-test-3.10-pyside6:
#  variables:
#    QT_API: pyside6
#  image: python:3.10
#  extends: ".run-test"
#  allow_failure: true
#
#run-test-3.10-pyqt6:
#  variables:
#    QT_API: pyqt6
#  image: python:3.10
#  extends: ".run-test"
#  allow_failure: true

run-doc-test:
  variables:
    QT_API: pyside2
  image: python:3.10
  stage: test
  script:
    - pip install -r requirements_doc.txt
    - sphinx-build -b html docs_sphinx public

pages:
  variables:
    QT_API: pyqt5
  stage: deploy
  image: python:3.10
  script:
    - pip install -r requirements_doc.txt
    - sphinx-build -b html docs_sphinx public
  artifacts:
    paths:
      - public
  only:
    - master
