name: Create GitHub Release from Tag

# Trigger: annotated tag pushed (vX.Y.Z)
on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Build concise release notes
        id: release_notes
        env:
          RELEASE_TAG: ${{ github.ref_name }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          python .github/scripts/build_release_notes.py /tmp/release_body.md
          echo "tag=${RELEASE_TAG}" >> "$GITHUB_OUTPUT"

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ steps.release_notes.outputs.tag }}
          name: ${{ steps.release_notes.outputs.tag }}
          body_path: /tmp/release_body.md
          draft: false
          prerelease: false
          generate_release_notes: false
