name: Test

# https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    name: Execute full unit test suite
    strategy:
      fail-fast: false
      matrix:
        node-version: [14.x, 16.x, 18.x]
        os: [macOS-latest, ubuntu-latest]
    runs-on: ${{ matrix.os }}

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: node_modules cache
        uses: actions/cache@v4
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

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

      - name: Install dependencies
        run: |
          yarn install --frozen-lockfile --network-timeout 300000

      - name: Build and run tests
        run: |
          make test
