name: Publish to PyPI

on:
  push:
    tags:
      - "v*"

jobs:
  call-tests:
    uses: ./.github/workflows/_tests.yml

  publish:
    name: Build and publish
    needs: call-tests
    runs-on: ubuntu-latest
    environment:
      name: pypi
    permissions:
      id-token: write
      contents: write
    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        uses: astral-sh/setup-uv@v5

      - name: Set up Python
        run: uv python install 3.12

      - name: Build and Publish
        run: |
          uv build
          uv publish
          
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/*
          generate_release_notes: true
