name: Test Release Notes Formatting 📝

on:
  workflow_dispatch:

permissions:
  contents: write

jobs:
  test-release-notes:
    name: Preview Release Notes
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0

      # Use the latest existing tag to test with real merged PR data
      - name: Get latest tag
        id: latest-tag
        run: |
          LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
          if [ -n "$LATEST_TAG" ]; then
            # Extract version number (remove 'v' prefix)
            VERSION="${LATEST_TAG#v}"
            echo "Using existing tag $LATEST_TAG for testing"
          else
            # Fallback to CMakeLists version
            VERSION=$(grep -Po 'project\(lemon_cpp VERSION \K[0-9]+\.[0-9]+\.[0-9]+' CMakeLists.txt)
            echo "No tags found, using CMakeLists version $VERSION"
          fi
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Generate release notes
        uses: ./.github/actions/generate-release-notes
        with:
          version: ${{ steps.latest-tag.outputs.version }}
          repo: ${{ github.repository }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: Upload preview
        uses: actions/upload-artifact@v7
        with:
          name: release-notes-preview
          path: release_notes.md
          retention-days: 7
