name: Publish to PyPI
on:
  release:
    types: [published]

jobs:
  publish:
    name: Release build and publish
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4

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

      - name: Build package
        run: |
          python -m pip install setuptools wheel build
          python setup.py sdist bdist_wheel

      - name: Publish package
        run: |
          python -m pip install twine
          python -m twine upload -r pypi dist/*
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: {{ '${{ secrets.PYPI_TOKEN }}' }}
          TWINE_NON_INTERACTIVE: true
