name: CI

on:
  push:
    paths-ignore:
        - 'docs/**'
        - '*.md'
  pull_request:
    paths-ignore:
        - 'docs/**'
        - '*.md'

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node-version: [12, 14, 16]
        os: [macos-latest, ubuntu-latest, windows-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v2.4.0
      - name: Use Node.js
        uses: actions/setup-node@v2.4.1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Restore cached dependencies
        uses: actions/cache@v2.1.6
        with:
          path: node_modules
          key: node-modules-${{ hashFiles('package.json') }}
      - name: Install dependencies
        run: npm install
      - name: Run Tests
        run: npm run test-ci
      - name: Coveralls Parallel
        uses: coverallsapp/github-action@1.1.3
        with:
          github-token: ${{ secrets.github_token }}
          parallel: true
          flag-name: run-${{ matrix.node-version }}-${{ matrix.os }}

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

  automerge:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: fastify/github-action-merge-dependabot@v2.5.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
