name: CI

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - uses: pre-commit/action@v3.0.1

  test:
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
        os:
          - ubuntu-latest
          - macOS-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - uses: snok/install-poetry@v1
      - name: Install Dependencies
        run: poetry install
      - name: Test with Pytest
        run: poetry run pytest --cov=./ --cov-report=xml --cov-report=term-missing tests/test_init.py
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - uses: snok/install-poetry@v1
      - name: Install Dependencies
        run: poetry install -E docs
      - name: Build docs
        working-directory: docs
        run: poetry run make html

  release:
    runs-on: ubuntu-latest
    environment: release
    if: github.ref == 'refs/heads/main'
    needs:
      - test
      - lint

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      # Run semantic release:
      # - Update CHANGELOG.md
      # - Update version in code
      # - Create git tag
      # - Create GitHub release
      # - Publish to PyPI
      - name: Python Semantic Release
        uses: python-semantic-release/python-semantic-release@v7.34.6
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          pypi_token: ${{ secrets.PYPI_TOKEN }}
