# This workflow will install Python dependencies, run tests and lint
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test

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

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repository
        uses: actions/checkout@v7.0.1

      - name: Set up Python 3.14
        uses: actions/setup-python@v7.0.0
        with:
          python-version: "3.14"

      - name: Install dependencies
        run: |
          python -m venv venv
          . venv/bin/activate
          python --version
          pip install uv
          uv pip install -r requirements_dev.txt -e .

      - name: Run pre-commit
        run: |
          . venv/bin/activate
          pre-commit run --all-files --show-diff-on-failure

  pytest:
    name: pytest ${{ matrix.python-version }}
    runs-on: ubuntu-latest
    needs: pre-commit
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11", "3.12", "3.13", "3.14"]

    steps:
      - name: Check out the repository
        uses: actions/checkout@v7.0.1

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v7.0.0
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        run: |
          python -m venv venv
          . venv/bin/activate
          python --version
          pip install uv
          uv pip install -r requirements_dev.txt -e .

      - name: Run tests
        run: |
          . venv/bin/activate
          pytest tests --cov=aioimmich --cov-report=xml

  codecov:
    name: codecov
    runs-on: ubuntu-latest
    needs: pytest

    steps:
      - name: Check out the repository
        uses: actions/checkout@v7.0.1

      - name: Set up Python 3.14
        uses: actions/setup-python@v7.0.0
        with:
          python-version: "3.14"

      - name: Install dependencies
        run: |
          python -m venv venv
          . venv/bin/activate
          python --version
          pip install uv
          uv pip install  -r requirements_dev.txt -e .

      - name: Run tests
        run: |
          . venv/bin/activate
          pytest tests --cov=aioimmich --cov-report=xml

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v7
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
