name: 3. Publish to TestPyPI (manual)

on:
  workflow_dispatch:

permissions:
  contents: read
  id-token: write

jobs:
  build-and-publish-testpypi:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.13'

      - name: Setup uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true

      - name: Sync deps and build dist
        shell: bash
        run: |
          set -euo pipefail
          uv python install 3.13
          uv venv --python 3.13
          source .venv/bin/activate
          uv sync --all-groups
          # Build sdist and wheel using hatchling via uv
          uv build
          ls -l dist

      - name: Publish to TestPyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url: https://test.pypi.org/legacy/
          # If you prefer API token mode instead of Trusted Publishing, uncomment and set TEST_PYPI_API_TOKEN secret:
          # password: ${{ secrets.TEST_PYPI_API_TOKEN }}
