name: Publish to PyPI

on:
  workflow_dispatch:

jobs:
  pypi-publish:
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    environment: pypi-package

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python 3.12.2
        uses: actions/setup-python@v4
        with:
          python-version: "3.12.2"

      - name: Install build tools
        run: |
          python -m pip install --upgrade pip
          pip install build twine

      - name: Build package
        run: |
          python -m build

      # TODO: Run tests against the built wheel

      - name: Publish to PyPI
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          python -m twine upload dist/*