name: CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest

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

    steps:
      - uses: actions/checkout@v6
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}
          cache: npm
          cache-dependency-path: package-lock.json
      - run: npm ci
      - run: npm run build
      - run: npm run test -- --coverage
      - run: npm run lint
        if: matrix.node-version == '25.x'
      - run: npm run type-check
        if: matrix.node-version == '25.x'
      - run: |
          npm run codegen
          if git diff --exit-code src/fit_types.ts; then
            echo "✓ src/fit_types.ts is unchanged after codegen"
          else
            echo "✗ src/fit_types.ts has been modified - please commit the changes"
            exit 1
          fi
        if: matrix.node-version == '25.x'
