name: Release

on:
  push:
    tags:
      - 'v*.*.*'  # Triggers on version tags like v1.1.0, v1.2.3, etc.

permissions:
  contents: write  # Required for creating releases

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [22, 24, 25]

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run Biome lint
        run: npx biome check src --diagnostic-level=error

      - name: Build project
        run: npm run build

      - name: Run tests
        run: npm test

  release:
    needs: test
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Extract version from tag
        id: version
        run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          generate_release_notes: true
          draft: false
          prerelease: false
          body: |
            ## Installation

            ```bash
            npm install @mcp-abap-adt/core
            ```

            See [Installation Guide](https://github.com/${{ github.repository }}/blob/main/doc/installation/INSTALLATION.md) for details.

            ## What's Changed
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
