name: CI
on: [push, pull_request]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4

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

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install hatch hatchling coverage

      - name: Install
        run: python -m pip install .[tests]

      - name: Test
        run: coverage run -m pytest

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  docs:
    needs: build-and-test
    permissions:
      pages: write
      id-token: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install hatch hatchling

      - name: Install
        run: pip install .[docs]

      - name: Build documentation
        run: |
          cd docs
          make html
  release:
    if: ${{ github.ref == 'refs/heads/main' }}
    needs:
      - docs
      - build-and-test
    permissions:
      contents: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - uses: google-github-actions/release-please-action@v4
        with:
          token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
