name: Publish to PyPI

on:
  release:
    types: [published]

permissions:
  contents: read

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

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"
          cache: pip

      - name: Build dists
        run: |
          python -m pip install --upgrade pip
          pip install build twine
          python -m build
          twine check dist/*

      - name: Publish to PyPI
        # Uses an API token stored as a GitHub Actions secret: PYPI_TOKEN
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.PYPI_TOKEN }}
