stages:
  - test
  - release

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
  paths:
    - .cache/pip

linter:
  stage: test
  image: python:3.10

  cache:
    paths:
      - .cache/pip
      - .cache/pre-commit

  except:
    - schedules

  variables:
    PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"

  before_script:
    - pip install pre-commit

  script:
    - pre-commit run -a

tests:
  stage: test
  image: python:3.10

  cache:
    paths:
      - .cache/pip

  before_script:
    - pip install tox

  script:
    - tox

  # Process coverage report so that it shows up in Gitlab interface
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'

bump-python-deps:
  stage: release
  image: registry.gitlab.teklia.com/infra/devops:latest

  only:
    - schedules

  script:
    - devops python-deps requirements.txt

deploy-pypi:
  stage: release
  image: python:3.10

  only:
    - tags

  before_script:
    - pip install twine build

  script:
    - python -m build
    - twine upload -r pypi dist/*