name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  ci:
    name: All
    runs-on: ubuntu-latest

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

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

      - name: Install dependencies
        run: yarn install

      - name: Type check
        run: echo skipping #npx tsc --noEmit

      - name: Lint
        run: npm run lint

      - name: Run Jest tests
        run: npm run test tests/jest

#      - name: Build app
#        env:
#          DATABASE_URL: ${{ secrets.DATABASE_URL }}
#        run: npm run build

      # Optional: Playwright E2E tests
      - name: Install Playwright deps
        run: npx playwright install --with-deps
#        npm install @playwright/test
#       npx playwright install

      - name: Run E2E tests
        env:
          NEXT_PUBLIC_API_URL: localhost:8088
          NEXT_PUBLIC_FIREBASE_ENV: PROD
          NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
          NEXT_PUBLIC_SUPABASE_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_KEY }}
        run: |
          yarn --cwd=web serve &
          npx wait-on http://localhost:3000
          npx playwright test tests/playwright
          SERVER_PID=$(fuser -k 3000/tcp)
          echo $SERVER_PID
          kill $SERVER_PID
