name: Publish to PyPI

on:
  push:
    tags:
      - 'v*'  # This workflow ONLY runs with a tag like v0.3.0, v0.3.1, etc.

jobs:
  pypi-publish:
    name: Build and publish Python distribution
    runs-on: ubuntu-latest
    
    # These permissions are required for PyPI Trusted Publishing
    environment: release
    permissions:
      id-token: write
      contents: read

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.9'

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

      - name: Build the tarball and wheel
        run: python -m build

      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1