name: Build

on:
    # TODO Can we make this workflow depend on unittests to avoid building broken packages?
    # As it seems: no, we cannot. At least not really. Jobs can depend on other jobs, but workflows
    # cannot depend on other workflows. But jobs cannot be triggered by events, only workflows are
    # triggered by events. That means we would need to run the build/upload job for every commit
    # and every Python version and then check if it is the right Python version and if there is a
    # new tag and only then really upload a package.
    # The only additional advantage of this approach might be that we could test the package
    # building process for every commit and every Python version comfortably.
    #
    # Note: building the package is also tested in unittests.yml.
    #
    # https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482/2
    # https://docs.github.com/en/actions/learn-github-actions/managing-complex-workflows#creating-dependent-jobs
    push:
      tags:
        - v*

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v6

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

    - name: Upgrade pip and install build tools
      run: |
        python -m pip install --upgrade pip
        pip install build

    - name: Build a binary wheel and a source tarball
      run: python -m build

    - name: Publish distribution package to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        password: ${{ secrets.PYPI_API_TOKEN }}
