name: CI

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  build-and-test:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node-version: [22, 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
        continue-on-error: true

      - name: Verify package can be created
        if: matrix.os == 'ubuntu-latest' && matrix.node-version == 22
        run: npm pack

      - name: Test package installation (Unix)
        if: matrix.os == 'ubuntu-latest' && matrix.node-version == 22
        run: |
          PACKAGE_FILE=$(ls mcp-abap-adt-core-*.tgz)
          npm install -g "./$PACKAGE_FILE"
          mcp-abap-adt --help || true
