image: python:3.11-bullseye

stages:
  - build
  - format
  - test-jobs
  - test-tasks

before_script:
  - poetry config virtualenvs.in-project true

cache:
  paths:
    - .venv

build-env:
  stage: build
  script:
  - pip install poetry
  - poetry --version
  - cd build/
  - poetry install --no-root

format:
  stage: format
  script:
    - export VIRTUALENV_NAME=$(ls .venv)
    - source .venv/$VIRTUALENV_NAME/bin/activate
    - poetry run pre-commit install
    - poetry run yapf -i -r -p .
    - poetry run ruff .
    - poetry run ruff . --fix

test-jobs:
  stage: test-jobs
  script:
    - export VIRTUALENV_NAME=$(ls .venv)
    - source .venv/$VIRTUALENV_NAME/bin/activate
    - export PYTHONPATH="$PYTHONPATH:$CI_PROJECT_DIR/jobs/src"
    - poetry run pytest jobs/tests/

test-tasks:
  stage: test-tasks
  script:
    - export VIRTUALENV_NAME=$(ls .venv)
    - source .venv/$VIRTUALENV_NAME/bin/activate
    - export PYTHONPATH="$PYTHONPATH:$CI_PROJECT_DIR/tasks/src"
    - poetry run pytest tasks/tests/