name: Publish to PyPI

on:
  push:
    tags:
      - 'v*'

jobs:
  # Tag pushes do not trigger ci.yml on their own; run the full suite
  # here so nothing reaches PyPI without passing tests.
  test:
    uses: ./.github/workflows/ci.yml

  build:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7
      - uses: astral-sh/setup-uv@v7
      - name: Build
        run: uv build
      - uses: actions/upload-artifact@v7
        with:
          name: dist
          path: dist/

  publish:
    needs: [test, build]
    runs-on: ubuntu-latest
    environment: pypi
    permissions:
      id-token: write
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: dist
          path: dist/
      - uses: pypa/gh-action-pypi-publish@release/v1
