|
| 1 | +name: E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'frontend/**' |
| 9 | + - 'backend/**' |
| 10 | + - 'docker-compose.test.yml' |
| 11 | + - '.github/workflows/e2e-tests.yml' |
| 12 | + pull_request: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + paths: |
| 16 | + - 'frontend/**' |
| 17 | + - 'backend/**' |
| 18 | + - 'docker-compose.test.yml' |
| 19 | + - '.github/workflows/e2e-tests.yml' |
| 20 | + |
| 21 | +jobs: |
| 22 | + e2e: |
| 23 | + name: Playwright E2E Tests |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 30 |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: '20' |
| 37 | + cache: 'npm' |
| 38 | + cache-dependency-path: frontend/package-lock.json |
| 39 | + |
| 40 | + - name: Install frontend dependencies |
| 41 | + working-directory: frontend |
| 42 | + run: npm ci |
| 43 | + |
| 44 | + - name: Install Playwright browsers |
| 45 | + working-directory: frontend |
| 46 | + run: npx playwright install --with-deps chromium |
| 47 | + |
| 48 | + - name: Start test environment |
| 49 | + run: docker compose -f docker-compose.test.yml up -d --build |
| 50 | + |
| 51 | + - name: Wait for backend to be healthy |
| 52 | + run: | |
| 53 | + echo "Waiting for backend health check..." |
| 54 | + for i in $(seq 1 24); do |
| 55 | + if curl -sf http://localhost:8001/health; then |
| 56 | + echo "Backend is healthy!" |
| 57 | + break |
| 58 | + fi |
| 59 | + echo "Attempt $i/24 — backend not ready yet, waiting 10s..." |
| 60 | + sleep 10 |
| 61 | + done |
| 62 | + # Final check — fail loudly if still not healthy |
| 63 | + curl -sf http://localhost:8001/health || (echo "Backend failed to become healthy" && exit 1) |
| 64 | +
|
| 65 | + - name: Wait for frontend health check |
| 66 | + run: | |
| 67 | + timeout 60 bash -c ' |
| 68 | + until curl -sf http://localhost:3001; do |
| 69 | + echo "Frontend not ready, retrying in 5s..." |
| 70 | + sleep 5 |
| 71 | + done |
| 72 | + ' |
| 73 | +
|
| 74 | + - name: Dump container logs (always) |
| 75 | + if: always() |
| 76 | + run: | |
| 77 | + echo "===== DB logs =====" |
| 78 | + docker compose -f docker-compose.test.yml logs db || true |
| 79 | + echo "===== Backend logs =====" |
| 80 | + docker compose -f docker-compose.test.yml logs backend || true |
| 81 | + echo "===== Frontend logs =====" |
| 82 | + docker compose -f docker-compose.test.yml logs frontend || true |
| 83 | +
|
| 84 | + - name: Upload container logs on failure |
| 85 | + if: failure() |
| 86 | + run: | |
| 87 | + mkdir -p /tmp/container-logs |
| 88 | + docker compose -f docker-compose.test.yml logs db > /tmp/container-logs/db.log 2>&1 || true |
| 89 | + docker compose -f docker-compose.test.yml logs backend > /tmp/container-logs/backend.log 2>&1 || true |
| 90 | + docker compose -f docker-compose.test.yml logs frontend > /tmp/container-logs/frontend.log 2>&1 || true |
| 91 | +
|
| 92 | + - name: Upload container logs artifact |
| 93 | + if: failure() |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: container-logs |
| 97 | + path: /tmp/container-logs/ |
| 98 | + retention-days: 7 |
| 99 | + |
| 100 | + - name: Run Playwright tests |
| 101 | + working-directory: frontend |
| 102 | + env: |
| 103 | + PLAYWRIGHT_BASE_URL: http://localhost:3001 |
| 104 | + PLAYWRIGHT_API_URL: http://localhost:8001 |
| 105 | + E2E_ADMIN_EMAIL: admin@test.com |
| 106 | + E2E_ADMIN_PASSWORD: password123 |
| 107 | + run: npx playwright test --project=chromium |
| 108 | + |
| 109 | + - name: Upload Playwright HTML report on failure |
| 110 | + if: failure() |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: playwright-report |
| 114 | + path: frontend/playwright-report/ |
| 115 | + retention-days: 7 |
| 116 | + |
| 117 | + - name: Upload screenshots on failure |
| 118 | + if: failure() |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: playwright-screenshots |
| 122 | + path: frontend/test-results/ |
| 123 | + retention-days: 7 |
| 124 | + |
| 125 | + - name: Tear down test environment |
| 126 | + if: always() |
| 127 | + run: docker compose -f docker-compose.test.yml down -v --remove-orphans || true |
0 commit comments