name: Library Tests

on: pull_request

jobs:
  test-matrix:
    strategy:
      matrix:
        node: [ '12', '14' ]
    name: Test Library Node v ${{ matrix.node }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Setup NodeJS
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}
      - name: Cache node modules
        id: cache-node-modules
        uses: actions/cache@v1
        with:
            path: ./node_modules
            key: test-${{ matrix.node }}-${{hashFiles('./yarn.lock')}}
            restore-keys: test-${{ matrix.node }}-${{hashFiles('./yarn.lock')}}
      - name: Install modules
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: yarn install
      - name: Run tests
        run: yarn test
      - name: Lint code
        run: yarn lint
      - name: Lint commit
        run: yarn commitlint $( git log -1 --pretty=format:"%s" )

  test-success:
    runs-on: ubuntu-latest
    needs: test-matrix
    steps:
      - name: Tests completed
        run: echo Done!
