image: python

stages:
  - test
  - build
  - deploy
  - release

check:
  stage: test
  before_script:
    - pip3 install black 'pylint<3' 'isort[colors]<6'
  script:
    - pip3 install --editable .
    - black --check --diff --color .
    - isort --check --diff --color .
    - pylint src/finam

test:
  stage: test
  script:
    - pip3 install --editable .[test]
    - python -m pytest --cov finam --cov-report term-missing --cov-report html:cov --cov-report xml:cov.xml -v tests/
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: cov.xml
    paths:
      - cov

doctest:
  stage: test
  script:
    - pip3 install --editable .[doc]
    # doctest does not detect tests in code files during the first run.
    # add a dummy build to generate .rst files before the actual tests
    - sphinx-build -b dummy docs/source docs/build
    - sphinx-build -b doctest docs/source docs/build

documentation:
  stage: build
  script:
    - pip3 install --editable .[doc]
    - sphinx-build docs/source docs/build
    - mv docs/build public/
  artifacts:
    paths:
      - public

pages:
  stage: deploy
  script: "true"
  artifacts:
    paths:
      - public
  only:
    - main

pypi_release:
  stage: release
  script:
    - pip install build twine
    - python -m build
    - python -m twine upload -u __token__ -p ${PYPI_TOKEN} dist/*
  only:
    - tags