# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml

# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:3.10

variables:
  HTTP_PROXY: "http://webproxy:8080"
  HTTPS_PROXY: "http://webproxy:8080"
  http_proxy: "http://webproxy:8080"
  https_proxy: "http://webproxy:8080"

.install-deps: &install-deps
  - poetry install

before_script:
  - pip install --upgrade pip virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install --upgrade pip poetry

quick-test:
  rules:
    - if: $CI_COMMIT_TAG == null
  script:
    - poetry install --with test
    - pytest -m "not webtest" --verbose --cov=zema_emc_annotated
          --junitxml=junit.xml
    - coverage xml
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  artifacts:
    when: always
    paths:
      - junit.xml
      - coverage.xml
    reports:
      junit: junit.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml

online-test:
  rules:
    - if: $CI_COMMIT_TAG == null
  script:
    - poetry install --with test
    - pytest -m webtest --verbose --cov=zema_emc_annotated
          --junitxml=junit.xml
    - coverage xml
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  artifacts:
    when: always
    paths:
      - junit.xml
      - coverage.xml
    reports:
      junit: junit.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml

mypy:
  rules:
    - if: $CI_COMMIT_TAG == null
      changes:
        - "**/*.py"
  script:
    - poetry install --with lint
    - mypy .

pylint:
  rules:
    - if: $CI_COMMIT_TAG == null
      changes:
        - "**/*.py"
  script:
    - poetry install --with lint
    - pylint src/zema_emc_annotated

flake8:
  rules:
    - if: $CI_COMMIT_TAG == null
      changes:
        - "**/*.py"
  script:
    - poetry install --only lint
    - flake8 .

sphinx:
  rules:
    - if: $CI_COMMIT_TAG == null
  script:
    - poetry install --with docs
    - apt update
    - apt -y install pandoc
    - sphinx-build -W --keep-going docs/ docs/_build

black:
  rules:
    - if: $CI_COMMIT_TAG == null
      changes:
        - "**/*.py"
  script:
    - poetry install --only dev
    - black --check .

release:
  rules:
    - if: $CI_COMMIT_TAG == null
  stage: deploy
  script:
    - poetry install --with release
    - git config --global user.name "Bjoern Ludwig"
    - git config --global user.email "bjoern.ludwig@ptb.de"
    - semantic-release --verbosity=DEBUG publish
  environment: production
