name: CI

on:
  push:
    branches: [main]
    paths-ignore:
      - '.github/**'
      - 'README.md'
  pull_request:
    branches: [main]

jobs:
  test:
    name: Test on ${{ matrix.os }} ${{ matrix.arch }} with Node.js ${{ matrix.node-version }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest, macos-15-intel]
        node-version: [20.x, 22.x, 24.x]
        arch: [x64]
        include:
          - os: windows-latest
            node-version: 20.x
            arch: x86
          - os: windows-latest
            node-version: 22.x
            arch: x86

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

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

      - name: Install dependencies
        run: npm ci

      - name: Build native tests
        run: npm run build

      - name: Run native tests
        run: npm run test

      - name: Prebuild
        run: npm run prebuild
