---
name: Testing

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - main
    paths:
      - "**.py"
      - "pyproject.toml"
      - "uv.lock"
      - "pypaperless/**"
      - "tests/**"
  pull_request:
    paths:
      - "**.py"
      - "pyproject.toml"
      - "uv.lock"
      - "pypaperless/**"
      - "tests/**"
  workflow_dispatch:

env:
  DEFAULT_PYTHON: "3.13"

jobs:
  pytest:
    name: Python ${{ matrix.python }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python: ["3.12", "3.13"]
    steps:
      - name: ⤵️ Check out code from GitHub
        uses: actions/checkout@v4.2.2
      - name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
        id: python
        uses: actions/setup-python@v5.6.0
        with:
          python-version: ${{ env.DEFAULT_PYTHON }}
      - name: 🏗 Set up uv
        run: |
          pipx install uv
          uv venv
      - name: 🏗 Install Python dependencies
        run: uv sync --group dev
      - name: 🚀 Run pytest
        run: uv run pytest -v --cov-report xml:coverage.xml --cov pypaperless tests
      - name: ⬆️ Upload coverage artifact
        uses: actions/upload-artifact@v4.6.2
        with:
          name: coverage-${{ matrix.python }}
          path: coverage.xml

  coverage:
    runs-on: ubuntu-latest
    needs: pytest
    steps:
      - name: ⤵️ Check out code from GitHub
        uses: actions/checkout@v4.2.2
        with:
          fetch-depth: 0
      - name: ⬇️ Download coverage data
        uses: actions/download-artifact@v4.3.0
      - name: 🚀 Upload coverage report
        uses: codecov/codecov-action@v5.4.3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true
