name: 'Tests: node.js'

on: [pull_request, push]

jobs:
  matrix:
    runs-on: ubuntu-latest
    outputs:
      latest: ${{ steps.set-matrix.outputs.requireds }}
    steps:
      - uses: ljharb/actions/node/matrix@main
        id: set-matrix
        with:
          type: 'majors'
          preset: '>=4'

  latest:
    needs: [matrix]
    name: 'latest majors'
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.matrix.outputs.latest) }}

    steps:
      - uses: actions/checkout@v2
      - uses: ljharb/actions/node/install@main
        name: 'nvm install ${{ matrix.node-version }} && npm install'
        with:
          node-version: ${{ matrix.node-version }}
          skip-ls-check: true
      - run: npm run tests-only
      - uses: codecov/codecov-action@v1

  node:
    name: 'node 4+'
    needs: [latest]
    runs-on: ubuntu-latest
    steps:
      - run: 'echo tests completed'
