name: Check

on:
  pull_request:
    branches:
      - main
      - next

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

env:
  NODE_OPTIONS: --max_old_space_size=6144

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v40

      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Prepare
        uses: ./.github/actions/prepare
        with:
          build: false

      - name: Run Linter
        run: pnpm exec eslint ${{ steps.changed-files.outputs.all_changed_files }}

  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Prepare
        uses: ./.github/actions/prepare
        with:
          build: false

      - name: Run Formatter
        run: pnpm exec prettier --check ${{ steps.changed-files.outputs.all_changed_files }}

  unit:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          # Vitest uses `git diff` under the hood to find the changed files in it's `--changed`
          # option, which in turn means we need to fetch the full git history so git is able to diff
          fetch-depth: 0

      - name: Prepare
        uses: ./.github/actions/prepare

      - name: Run Tests
        run: pnpm test -- -- --changed origin/${{ github.base_ref }} --passWithNoTests
