name: build-and-test

on:
  push:
    branches:
      - master
      - develop

  pull_request:
    branches:
      - master
      - develop

jobs:
  build-and-test:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [14]

    steps:
      - name: TurboRepo local server
        uses: felixmosh/turborepo-gh-artifacts@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

      - name: Checkout 🛎
        uses: actions/checkout@master

      - name: Setup node env 🏗
        uses: actions/setup-node@v2.1.2
        with:
          node-version: ${{ matrix.node }}
          check-latest: true

      - name: Get yarn cache directory path 🛠
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache node_modules 📦
        uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install dependencies 👨🏻‍💻
        run: yarn install --frozen-lockfile

      - name: Run linter 🧹
        run: yarn lint

      - name: Build Library 👷
        run: yarn build --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}"

      - name: Run tests 🧪
        run: yarn test
