name: tests
on:
  pull_request:
    branches:
      - master
      - develop
  push:
    branches:
      - master
      - develop

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    strategy:
      matrix:
        node: [12, 14, 16]
    name: Node ${{ matrix.node }} test
    steps:
      - name: Clone repository
        uses: actions/checkout@v2 
      - name: Set Node.js version ${{ matrix.node }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node }}
      - name: Install dependencies
        run: npm ci
      - name: Run tests
        run: npm test
      - name: Coveralls Parallel
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          flag-name: run-${{ matrix.node }}
          parallel: true

  finish:
    name: Coveralls Coverage
    needs: test
    runs-on: ubuntu-latest
    steps:
      - name: Coveralls Finished
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          parallel-finished: true
