name: deploy

on:
  release: # when new release created
    types: [published]

permissions:
  contents: read

jobs:
  release-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.13

      - name: Build release distributions
        run: |
          python -m pip install build
          python -m build

      - name: Upload distributions # upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: release-dists
          path: dist/

  release-publish:
    needs:
      - release-build
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: pypi
    permissions:
      id-token: write
    steps:
      - name: Download all the dists # download build artifacts saved in previous job
        uses: actions/download-artifact@v4
        with:
          name: release-dists
          path: dist/

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