name: Frontend CI (apps/web)

on:
  push:
    branches:
      - main
    paths:
      - 'apps/web/**'
      - 'package.json'
      - 'pnpm-lock.yaml'
      - '.github/workflows/frontend-ci.yml'

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

jobs:
  frontend-tests:
    name: Frontend Tests
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          run_install: false
          package_json_path: package.json

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'pnpm'

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

      - name: Type checking
        run: pnpm --filter=@my-roadtrip/web type-check

      - name: Run LoginPage tests
        run: pnpm --filter=@my-roadtrip/web test:unit -- LoginPage.spec.ts

      - name: Run all frontend tests
        run: pnpm --filter=@my-roadtrip/web test:unit

      - name: Test coverage
        run: pnpm --filter=@my-roadtrip/web test:coverage
        continue-on-error: true

      - name: Build frontend
        run: pnpm --filter=@my-roadtrip/web build

  frontend-lint:
    name: Frontend Lint & Quality
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          run_install: false
          package_json_path: package.json

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'pnpm'

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

      - name: Type check
        run: pnpm --filter=@my-roadtrip/web type-check
        continue-on-error: true
