image: python:3.11-bullseye

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

variables:
  POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/poetry"

cache:
  paths:
    - .cache/poetry

build-env:
  stage: build
  script:
  - pip install poetry
  - poetry --version
  - cd build/
  - poetry config virtualenvs.in-project true
  - poetry install --no-root
  # - poetry run pip install poetry
  artifacts:
    paths:
      - $POETRY_CACHE_DIR/virtualenvs/

test-jobs:
  stage: test-jobs
  script:
    - export VIRTUALENV_NAME=$(ls $POETRY_CACHE_DIR/virtualenvs)
    - source $POETRY_CACHE_DIR/virtualenvs/$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 $POETRY_CACHE_DIR/virtualenvs)
    - source $POETRY_CACHE_DIR/virtualenvs/$VIRTUALENV_NAME/bin/activate
    - export PYTHONPATH="$PYTHONPATH:$CI_PROJECT_DIR/tasks/src"
    - poetry run pytest tasks/tests/