# https://taskfile.dev

version: "3"

silent: true

includes:
  release: ./.github
  mongodb:
    taskfile: ./mongodb-cluster/Taskfile.yml
    dir: ./mongodb-cluster
    optional: true

tasks:
  full-test:
    desc: Run the tests against all supported versions.
    deps:
      - task: "mongodb:check"
    cmds:
      - tox --parallel auto

  test:
    desc: |
      Run the tests with the current version.
    deps:
      - task: "mongodb:check"
    cmds:
      - uv run python -m pytest -rs -n auto

  bench:
    desc: |
      Run the benches with the current version.
    deps:
      - task: "mongodb:check"
    cmds:
      - uv run python -m pytest --benchmark-enable --benchmark-only

  default:
    desc: |
      Run the tests related to changes with the current version.
    deps:
      - task: mongodb
    cmds:
      - uv run python -m pytest -rs --testmon

  coverage:
    desc: Get the test coverage (xml and html) with the current version.
    deps:
      - task: "mongodb:check"
    cmds:
      - coverage run -m pytest -rs
      - coverage report -m
      - coverage xml
      - 'echo "Generated XML report: ./coverage.xml"'
      - coverage html
      - 'echo "Generated HTML report: ./htmlcov/index.html"'

  docs:
    desc: Start the local documentation server.
    cmds:
      - mkdocs serve -f ./mkdocs.yml

  lint:
    desc: Run the linting checks.
    cmds:
      - pre-commit run --all-files

  format:
    desc: Format the code (and imports).
    cmds:
      - uv run python -m ruff check odmantic tests

  setup:
    desc: Configure the development environment.
    cmds:
      - task: setup:git-lfs
      - task: setup:git-submodules
      - task: setup:pre-commit-hook
      - task: setup:deps-setup

  setup:git-lfs:
    cmds:
      - git lfs install
      - git lfs pull
    status:
      - test -d .git/lfs/

  setup:git-submodules:
    cmds:
      - git submodule update --init
    status:
      - test -f .mongodb-cluster-action/README.md

  setup:pre-commit-hook:
    cmds:
      - pre-commit install
    status:
      - test -f .git/hooks/pre-commit

  setup:deps-setup:
    deps:
      - task: setup:uv
    cmds:
      - uv sync --all-extras --dev
    sources:
      - pyproject.toml

  setup:uv:
    cmds:
      - pip install uv
    status:
      - which uv

  clean:
    cmds:
      - rm -rf dist/
      - rm -rf htmlcov/ ./.coverage ./coverage.xml
      - rm -rf .task/ ./__release_notes__.md ./__version__.txt
