name: Publish to PyPI

on:
  workflow_dispatch:
    inputs:
      tag:
        description: "Git tag to build from"
        required: true

jobs:
  deploy:
    name: Publish Python package
    runs-on: ubuntu-latest

    steps:
      - name: Check out the code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.inputs.tag }}

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

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

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

      - name: Publish distribution to PyPI
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.PYPI_PASSWORD }}
