name: CI

on:
  push:
    branches: [master, v1.5-dev]
  pull_request:
    branches: [master, v1.5-dev]

jobs:
  linux:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version:
          - 4
          - 5
          - 6
          - 7
          - 8
          - 9
          - 10
          - 11
          - 12
          - 13
          - 14
          - 15
          - 16
          - 18
          - 20
          - 22
          - 24

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies
        run: npm install

      - name: Build
        run: npm run build

      - name: Test
        run: npm test

  macos:
    runs-on: macos-latest
    strategy:
      matrix:
        node-version:
          - 18
          - 20
          - 22
          - 24

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies
        run: npm install

      - name: Build
        run: npm run build

      - name: Test
        run: npm test

  browser:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js 24
        uses: actions/setup-node@v4
        with:
          node-version: 24

      - name: Install dependencies (no postinstall for old compat)
        run: npm install --ignore-scripts

      - name: Install browser test tools
        run: |
          npm install --save-dev --ignore-scripts @playwright/test esbuild
          npx playwright install chromium

      - name: Build (esbuild)
        run: npx esbuild src/pnglib.js --bundle --format=esm --outfile=browser-test/bundle.mjs

      - name: Browser test
        run: npx playwright test --config browser-test/playwright.config.js
