name: ci

on: [push, pull_request]

jobs:
  should-skip:
    continue-on-error: true
    runs-on: ubuntu-latest
    # Map a step output to a job output
    outputs:
      should-skip-job: ${{steps.skip-check.outputs.should_skip}}
    steps:
      - id: skip-check
        uses: fkirc/skip-duplicate-actions@v2.1.0
        with:
          github_token: ${{github.token}}

  ci:
    needs: should-skip
    # Never skip on the  main branch
    if: ${{needs.should-skip.outputs.should-skip-job != 'true' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'}}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        node: [12, 14, 16]
    runs-on: ${{matrix.os}}
    steps:

    - name: checkout code
      uses: actions/checkout@v2

    - name: setup node
      uses: actions/setup-node@v2
      with:
        node-version: '${{matrix.node}}'
        cache: npm

    # turn off the default setup-node problem watchers...
    - run: echo "::remove-matcher owner=eslint-compact::"
    - run: echo "::remove-matcher owner=eslint-stylish::"
    - run: echo "::remove-matcher owner=tsc::"

    - name: npm install
      run: npm i --prefer-offline --no-audit

    - name: run npm test
      run: npm run test

    - name: coverage
      uses: codecov/codecov-action@v1
      with:
        token: ${{secrets.CODECOV_TOKEN}}
        files: './coverage/coverage-final.json'
        fail_ci_if_error: true
