name: Latest Release

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  publish-release:
    name: upload release to PyPI
    runs-on: ubuntu-latest
    permissions:
      id-token: write
    environment: release
    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Install uv
        uses: astral-sh/setup-uv@v7
        with:
          version: "0.5.4"
          enable-cache: true

      - name: Build package
        run: uv build

      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1

  build-docs:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Install uv
        uses: astral-sh/setup-uv@v7
        with:
          version: "0.5.4"
          enable-cache: true

      - name: Install dependencies
        run: uv sync --all-extras

      - name: Build docs
        run: uv run make docs

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: docs/_build/html
