From fbd41f3cf8e9c56fefa5eae4f25e9b1d2cd85863 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Mon, 4 May 2026 17:50:15 +0530 Subject: [PATCH] ci: add E2E test workflow --- .github/workflows/e2e-tests.yml | 200 ++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 .github/workflows/e2e-tests.yml diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 000000000..3d2bcac07 --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,200 @@ +name: E2E Tests + +on: + pull_request: + branches: [main, dev] + types: [opened, synchronize, reopened, ready_for_review] + paths: + - 'surfsense_web/**' + - 'surfsense_backend/**' + - '.github/workflows/e2e-tests.yml' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + e2e: + name: Playwright E2E + runs-on: ubuntu-latest + if: github.event.pull_request.draft == false + timeout-minutes: 30 + env: + # Backend + DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_e2e + SECRET_KEY: ci-test-secret-key-not-for-production + AUTH_TYPE: LOCAL + ETL_SERVICE: DOCLING + EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2 + # Frontend (consumed by `next dev` via playwright.config.ts webServer.env) + NEXT_PUBLIC_FASTAPI_BACKEND_URL: http://localhost:8000 + NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE: LOCAL + # Playwright + PLAYWRIGHT_TEST_EMAIL: e2e-test@surfsense.test + PLAYWRIGHT_TEST_PASSWORD: E2eTestPassword123! + + services: + postgres: + image: pgvector/pgvector:pg17 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: surfsense_e2e + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres -d surfsense_e2e" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: '3.12' + + - name: Install uv + uses: astral-sh/setup-uv@v8.1.0 + + - name: Cache backend dependencies + uses: actions/cache@v5 + with: + path: | + ~/.cache/uv + surfsense_backend/.venv + key: python-deps-${{ hashFiles('surfsense_backend/uv.lock') }} + restore-keys: | + python-deps- + + - name: Cache HuggingFace models + uses: actions/cache@v5 + with: + path: ~/.cache/huggingface + key: hf-models-${{ env.EMBEDDING_MODEL }} + + - name: Install backend dependencies + working-directory: surfsense_backend + run: uv sync + + - name: Run database migrations + working-directory: surfsense_backend + run: uv run alembic upgrade head + + - name: Start backend + working-directory: surfsense_backend + run: | + uv run uvicorn main:app --host 0.0.0.0 --port 8000 \ + > backend.log 2>&1 & + echo $! > backend.pid + + - name: Wait for backend readiness + run: | + for i in $(seq 1 60); do + if curl -sf http://localhost:8000/openapi.json > /dev/null; then + echo "Backend is up" + exit 0 + fi + sleep 2 + done + echo "Backend failed to start within 120s" + cat surfsense_backend/backend.log + exit 1 + + - name: Register E2E test user + run: | + # Idempotent: 200/201 = created, 400 = already exists (also OK) + STATUS=$(curl -s -o /tmp/register.json -w "%{http_code}" \ + -X POST http://localhost:8000/auth/register \ + -H "Content-Type: application/json" \ + -d "{\"email\":\"${PLAYWRIGHT_TEST_EMAIL}\",\"password\":\"${PLAYWRIGHT_TEST_PASSWORD}\"}") + echo "Register status: ${STATUS}" + cat /tmp/register.json + if [ "${STATUS}" != "200" ] && [ "${STATUS}" != "201" ] && [ "${STATUS}" != "400" ]; then + echo "Failed to register test user (status ${STATUS})" + exit 1 + fi + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: '20' + + - name: Install pnpm + uses: pnpm/action-setup@v6 + with: + version: 10 + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT + + - name: Cache pnpm store + uses: actions/cache@v5 + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: pnpm-${{ runner.os }}-${{ hashFiles('surfsense_web/pnpm-lock.yaml') }} + restore-keys: | + pnpm-${{ runner.os }}- + + - name: Install web dependencies + working-directory: surfsense_web + run: pnpm install --frozen-lockfile + + - name: Cache Playwright browsers + id: playwright-cache + uses: actions/cache@v5 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ hashFiles('surfsense_web/pnpm-lock.yaml') }} + + - name: Install Playwright browsers + if: steps.playwright-cache.outputs.cache-hit != 'true' + working-directory: surfsense_web + run: pnpm exec playwright install --with-deps chromium + + - name: Install Playwright system deps (cache hit) + if: steps.playwright-cache.outputs.cache-hit == 'true' + working-directory: surfsense_web + run: pnpm exec playwright install-deps chromium + + - name: Run Playwright tests + working-directory: surfsense_web + run: pnpm test:e2e + + - name: Upload Playwright HTML report + if: always() + uses: actions/upload-artifact@v7 + with: + name: playwright-report + path: surfsense_web/playwright-report/ + retention-days: 14 + + - name: Upload Playwright traces + if: failure() + uses: actions/upload-artifact@v7 + with: + name: playwright-traces + path: surfsense_web/test-results/ + retention-days: 14 + + - name: Upload backend log + if: failure() + uses: actions/upload-artifact@v7 + with: + name: backend-log + path: surfsense_backend/backend.log + retention-days: 7 + + - name: Stop backend + if: always() + working-directory: surfsense_backend + run: | + if [ -f backend.pid ]; then + kill "$(cat backend.pid)" 2>/dev/null || true + fi