# Test Workflow - GitHub Actions
# Generated by pypreset augment

name: Tests

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["{{ project.python_version }}", "3.12"]

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python {% raw %}${{ matrix.python-version }}{% endraw %}

        uses: actions/setup-python@v5
        with:
          python-version: {% raw %}${{ matrix.python-version }}{% endraw %}

{% if package_manager == "poetry" %}
      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v4
        with:
          path: .venv
          key: {% raw %}venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}{% endraw %}

      - name: Install dependencies
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        run: poetry install --no-interaction --no-root

      - name: Install project
        run: poetry install --no-interaction

{% if testing.framework == "pytest" %}
{% if testing.coverage %}
      - name: Run tests with coverage
        run: poetry run pytest --cov={{ project.package_name }} --cov-report=xml --cov-report=term-missing

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: false
{% else %}
      - name: Run tests
        run: poetry run pytest -v
{% endif %}
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: poetry run python -m unittest discover -s tests -v
{% endif %}
{% elif package_manager == "pdm" %}
      - name: Install PDM
        uses: pdm-project/setup-pdm@v4
        with:
          python-version: {% raw %}${{ matrix.python-version }}{% endraw %}


      - name: Install dependencies
        run: pdm install

{% if testing.framework == "pytest" %}
{% if testing.coverage %}
      - name: Run tests with coverage
        run: pdm run pytest --cov={{ project.package_name }} --cov-report=xml --cov-report=term-missing

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: false
{% else %}
      - name: Run tests
        run: pdm run pytest -v
{% endif %}
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: pdm run python -m unittest discover -s tests -v
{% endif %}
{% elif package_manager == "hatch" %}
      - name: Install Hatch
        run: pip install hatch

{% if testing.framework == "pytest" %}
{% if testing.coverage %}
      - name: Run tests with coverage
        run: hatch run test:cov

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: false
{% else %}
      - name: Run tests
        run: hatch run test
{% endif %}
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: hatch run python -m unittest discover -s tests -v
{% endif %}
{% else %}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[dev]"

{% if testing.framework == "pytest" %}
{% if testing.coverage %}
      - name: Run tests with coverage
        run: pytest --cov={{ project.package_name }} --cov-report=xml --cov-report=term-missing

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: false
{% else %}
      - name: Run tests
        run: pytest -v
{% endif %}
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: python -m unittest discover -s tests -v
{% endif %}
{% endif %}
