name: Publish to PyPI

on:
  push:
    tags:
    - '*'

jobs:
  build:
    name: Build distribution
    runs-on: ubuntu-latest
    if: github.event.repository.fork == false
    steps:
    - uses: actions/checkout@v7
    - uses: actions/setup-python@v7
      with:
        python-version: 3.x
    - name: Build
      run: |
        python -m pip install --upgrade build
        python -m build
    - uses: actions/upload-artifact@v7
      with:
        name: dist
        path: dist/

  publish:
    name: Publish to PyPI
    needs: build
    runs-on: ubuntu-latest
    environment: release
    permissions:
      id-token: write
    steps:
    - uses: actions/download-artifact@v8
      with:
        name: dist
        path: dist/
    - uses: pypa/gh-action-pypi-publish@release/v1
