name: Test

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  workflow_dispatch:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  test:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16.x'
      - uses: actions/cache@v2
        with:
          path: |
            ~/.npm
            ~/.config/yarn/global
          key: ${{ runner.os }}-node-server-api-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-node-server-api-

      - name: Install Yarn
        run: |
          npm install -g yarn
          yarn install

      - name: Lint
        run: yarn lint
      
      - name: Prettier
        run: yarn format:check

      - name: Test
        run: yarn test
