name: CI

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

jobs:
  ci:
    name: Tests
    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
        env:
          NEXT_PUBLIC_FIREBASE_ENV: DEV
        run: |
          yarn test:coverage
#          npm install -g lcov-result-merger
#          mkdir coverage
#          lcov-result-merger \
#          "backend/api/coverage/lcov.info" \
#          "backend/shared/coverage/lcov.info" \
#          "backend/email/coverage/lcov.info" \
#          "common/coverage/lcov.info" \
#          "web/coverage/lcov.info" \
#          > coverage/lcov.info

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

      - name: Run E2E tests
        run: |
          chmod +x scripts/e2e.sh
          ./scripts/e2e.sh

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: |
            backend/api/coverage/lcov.info
            backend/shared/coverage/lcov.info
            backend/email/coverage/lcov.info
            common/coverage/lcov.info
            web/coverage/lcov.info
          flags: unit
          fail_ci_if_error: true
          slug: CompassConnections/Compass
        env:
          CI: true
