name: CI

on:
  push:
    branches: [master]
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 26.x
          cache: npm
      - run: npm ci
      - run: npm run lint

  # Suites that need no X server: the pure-JS X server driven by our own
  # client over in-process stream pairs.
  test-xserver:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version: [22, 24, 26]
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node-version }}
          cache: npm
      - run: npm ci
      - run: npm run test:xserver
      - run: npm run test:glx-emu

  test:
    runs-on: ubuntu-latest
    # Tests run inside debian bookworm containers rather than on the runner:
    # ubuntu 24.04's Xvfb segfaults (NULL deref, server abort) on indirect
    # glXMakeCurrent, which the GLX tests exercise. Bookworm's Xvfb handles
    # indirect GLX correctly.
    container: node:${{ matrix.node-version }}-bookworm
    strategy:
      fail-fast: false
      matrix:
        node-version: [22, 24, 26]
    steps:
      - uses: actions/checkout@v7
      - name: Install Xvfb
        run: apt-get update && apt-get install -y xvfb
      - run: npm ci
      - name: Run tests under Xvfb
        run: xvfb-run -a -s "-screen 0 1280x1024x24 -nolisten tcp +iglx" npm test
