# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node.
# This workflow will be run whenever a new commit is pushed or when a PR is opened up.
# Guide: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build and Run Tests

on:
  # run this for every push (CI)
  push:
  # also run this for PR
  pull_request:

jobs:
  build:

    runs-on: ubuntu-latest

    # run this job for every combination of given matrix variables
    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x]

    steps:

    # checkout our repo for the current commit
    - name: Check out repo
      uses: actions/checkout@v3

    # setup specified node version
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'yarn'

    - name: Install dependencies
      run: yarn install --frozen-lockfile # do a clean install of all of our dependencies

    # build our library to catch any build errors
    - name: Build!
      run: yarn run build-dist

    # run all of our tests
    - name: Test!
      run: yarn test
