---
name: Testing

# yamllint disable-line rule:truthy
on:
  push:
  pull_request:
  workflow_dispatch:

env:
  DEFAULT_PYTHON: "3.11"

jobs:
  pytest:
    name: Python ${{ matrix.python }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python: ["3.11", "3.12", "3.13"]
    steps:
      - name: ⤵️ Check out code from GitHub
        uses: actions/checkout@v4.2.2
      - name: 🏗 Set up uv
        uses: astral-sh/setup-uv@v5.2.1
        with:
          enable-cache: true
          python-version: ${{ env.DEFAULT_PYTHON }}
      - name: 🏗 Install dependencies
        run: uv sync --extra cli --frozen --dev
      - name: 🚀 Run pytest
        run: uv run pytest --cov peblar tests
      - name: ⬆️ Upload coverage artifact
        uses: actions/upload-artifact@v4.6.0
        with:
          name: coverage-${{ matrix.python }}
          path: .coverage
          if-no-files-found: error
          include-hidden-files: true

  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.1.8
      - name: 🏗 Set up uv
        uses: astral-sh/setup-uv@v5.2.1
        with:
          enable-cache: true
          python-version: ${{ env.DEFAULT_PYTHON }}
      - name: 🏗 Install dependencies
        run: uv sync --extra cli --frozen --dev
      - name: 🚀 Process coverage results
        run: |
          uv run coverage combine coverage*/.coverage*
          uv run coverage xml -i
      - name: 🚀 Upload coverage report
        uses: codecov/codecov-action@v5.2.0
