name: Node.js CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - '**'

env:
  FORCE_COLOR: 2

permissions:
  contents: read

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

    strategy:
      fail-fast: true
      matrix:
        node: [14, 16, 18]
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
      - uses: actions/checkout@v3

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

      - name: Install dependencies
        run: npm i

      - name: Test
        run: npm run test

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3
        if: startsWith(matrix.os, 'ubuntu-latest') && matrix.node == 18
        with:
          files: ./coverage/lcov.info
