name: Publish to PyPI

on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: "3.12"

      - name: Install uv
        uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v4
        with:
          enable-cache: true

      - name: Install build & twine
        run: uv pip install --system build twine

      - name: Sync project dependencies
        run: uv sync --all-groups

      - name: Build distribution
        run: uv run python -m build --sdist --wheel

      - name: Publish package to PyPI
        env:
          TWINE_USERNAME: "__token__"
          TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
        run: uv run twine upload dist/*
