name: Node.js package

on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-2019]
        node_version: [16.x, 18.x, 20.x]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node_version }}
      - name: Install dependencies
        if: startsWith(runner.OS, 'windows') == false
        run: |
          sudo apt -qq update
          sudo apt install -y libudev-dev
      - name: Build Linux
        if: startsWith(runner.OS, 'windows') == false
        run: |
          export PATH=./node_modules/.bin:${PATH}
          npm install --build-from-source --node-gyp=$(which pangyp)
          ./node_modules/.bin/node-pre-gyp package
      - name: Build Windows
        if: startsWith(runner.OS, 'windows') == true
        run: |
          npm install --build-from-source
          ./node_modules/.bin/node-pre-gyp package
      - name: Test
        run: npm test
