name: Publish on PyPI
on: [push, workflow_dispatch, workflow_call]
jobs:
  build:
    name: Build distributions
    runs-on: ubuntu-24.04
    steps:
    - uses: actions/checkout@v7
      with:
        fetch-depth: 0
    - uses: actions/setup-python@v6
      with:
        python-version: "3.x"
    - run: pip install build
    - run: python -m build
    - uses: actions/upload-artifact@v7
      with:
        name: build
        path: dist/
  publish-to-pypi:
    name: Publish distributions to PyPI
    if: startsWith(github.ref, 'refs/tags/')
    needs:
      - build
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/download-artifact@v8
        with:
          pattern: build
          path: dist/
          merge-multiple: true
      - uses: pypa/gh-action-pypi-publish@release/v1
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}
