name: Test & Build
on: [pull_request]
jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: yarn
      - uses: actions/cache@v3
        id: yarn-cache
        with:
          path: node_modules
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: ${{ runner.os }}-yarn-

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Test with Coverage
        run: yarn coverage

      - name: ESLint
        run: yarn eslint

      - name: Report Coverage
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

  build:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: yarn
      - uses: actions/cache@v3
        id: yarn-cache
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: ${{ runner.os }}-yarn-

      - name: Install dependencies
        run: yarn install --frozen-lockfile --prefer-offline

      - name: Build Dist
        run: yarn build

      - name: Bundlewatch
        run: npx bundlewatch

      - name: Build Docs
        run: |
          cd docs
          yarn install --frozen-lockfile --prefer-offline
          yarn build
