# This workflow uploads a Python Package to PyPI using Poetry when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Pypi

on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  deploy:
    name: Publish python package
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
      uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version-file: pyproject.toml

    - name: Install Poetry
      run: |
        pipx install "poetry>=2.0.0,<3.0.0"

    - name: Install dependencies
      run: |
        poetry install --no-interaction --no-root

    - name: Build the package
      run: |
        poetry build

    # Step 6: Publish to PyPI
    - name: Publish to PyPI
      run: |
        poetry publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
