name: CI

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

jobs:
  check:
    name: Lint & Type-check
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        with:
          version: 9

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm

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

      - name: Type-check
        run: pnpm turbo run check

      - name: Lint
        run: pnpm turbo run lint
        continue-on-error: true  # lint warnings should not block CI initially

  build:
    name: Build
    runs-on: ubuntu-latest
    needs: check

    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        with:
          version: 9

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm

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

      - name: Build
        run: pnpm turbo run build
        env:
          # Placeholder values for build-time env vars
          PUBLIC_SUPABASE_URL: http://localhost:8000
          PUBLIC_SUPABASE_ANON_KEY: placeholder
          PUBLIC_KEYCLOAK_URL: http://localhost:8080
          PUBLIC_KEYCLOAK_REALM: colectivo
          PUBLIC_KEYCLOAK_CLIENT_ID: colectivo-web
          PUBLIC_APP_URL: http://localhost:5173
