name: Check PRs

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  FORCE_COLOR: 3
  NEXT_TELEMETRY_DISABLED: 1

jobs:
  check:
    name: Static analysis
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Restore cached node_modules
        uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
      - name: Install missing dependencies
        run: yarn install --prefer-offline --frozen-lockfile
      - name: Run Prettier on web client
        working-directory: web
        run: npx prettier --check .
      - name: Run ESLint on common
        if: ${{ success() || failure() }}
        working-directory: common
        run: npx eslint . --max-warnings 0
      - name: Run ESLint on web client
        if: ${{ success() || failure() }}
        working-directory: web
        run: yarn lint --max-warnings 0
      - name: Run ESLint on cloud functions
        if: ${{ success() || failure() }}
        working-directory: functions
        run: npx eslint . --max-warnings 0
      - name: Run Typescript checker on web client
        if: ${{ success() || failure() }}
        working-directory: web
        run: tsc --pretty --project tsconfig.json --noEmit
      - name: Run Typescript checker on cloud functions
        if: ${{ success() || failure() }}
        working-directory: functions
        run: tsc -b -v --pretty