name: Frontend CI

on:
  push:
    branches: [ "main", "dev" ]
    paths:
      - 'frontend/**'
  pull_request:
    branches: [ "main", "dev" ]
    paths:
      - 'frontend/**'

jobs:
  build-and-check:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: frontend

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

    - name: Setup pnpm
      uses: pnpm/action-setup@v4
      with:
        version: 10
        run_install: false

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '24.x'

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

    - name: Audit dependencies
      if: always()
      run: pnpm audit --audit-level moderate

    - name: Check formatting
      if: always()
      run: pnpm exec prettier --check src/

    - name: Lint with oxlint
      if: always()
      run: pnpm exec oxlint .

    - name: Lint with ESLint
      if: always()
      run: pnpm exec eslint . --max-warnings=0

    - name: Type check
      if: always()
      run: pnpm run type-check

    - name: Build
      if: always()
      run: pnpm run build-only
