name: Build And Test

on:
  pull_request:
    branches: [master, 1.x]

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x]

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: npm ci
      - name: Check commit messages
        run: npx commitlint --from origin/master
      - name: Check linting
        run: npm run lint
      - name: Build the project
        run: npm run build --if-present
      - name: Run the tests
        run: npm run test
