name: Release on Tag

on:
  push:
    tags:
      - 'v*'  # only triggers on tags like v1.0.0

jobs:
  release:
    name: Build and Publish Release
    runs-on: ubuntu-latest

    permissions:
      contents: write       # to create GitHub release
      id-token: write       # for OIDC (trusted publishing)

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

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'

      - name: Install Poetry
        run: |
          curl -sSL https://install.python-poetry.org | python3 -
          echo "$HOME/.local/bin" >> $GITHUB_PATH

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

      - name: Build the package
        run: poetry build

      - name: Create GitHub Release with Notes
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          name: Release ${{ github.ref_name }}
          generate_release_notes: true
          files: dist/*

      

      - name: Publish to PyPI with Poetry and token
        run: poetry publish --username __token__ --password ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
