|
| 1 | +name: E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + pull_request_target: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + branches: |
| 10 | + - develop |
| 11 | + |
| 12 | +# Cancel old builds on new commit for same workflow + branch/PR |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + initial-checks: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Setup Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: 'lts/*' |
| 31 | + cache: 'npm' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + e2e: |
| 37 | + needs: initial-checks |
| 38 | + runs-on: ubuntu-latest |
| 39 | + environment: production |
| 40 | + |
| 41 | + env: |
| 42 | + DATABASE_URL: "postgresql://postgres:secret@localhost:5432/postgres" |
| 43 | + NEXTAUTH_URL: http://localhost:3000/api/auth |
| 44 | + GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }} |
| 45 | + GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }} |
| 46 | + NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Checkout repository |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + ref: ${{ github.event.pull_request.head.sha }} |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Setup Node.js |
| 56 | + uses: actions/setup-node@v4 |
| 57 | + with: |
| 58 | + node-version: 'lts/*' |
| 59 | + cache: 'npm' |
| 60 | + |
| 61 | + - name: Cache Playwright browsers |
| 62 | + uses: actions/cache@v3 |
| 63 | + with: |
| 64 | + path: ~/.cache/ms-playwright |
| 65 | + key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-playwright- |
| 68 | +
|
| 69 | + - name: Run docker-compose |
| 70 | + |
| 71 | + with: |
| 72 | + compose-file: "./docker-compose.yml" |
| 73 | + down-flags: "--volumes" |
| 74 | + services: | |
| 75 | + db |
| 76 | +
|
| 77 | + - name: Wait for DB to be ready |
| 78 | + run: | |
| 79 | + timeout 60s bash -c 'until nc -z localhost 5432; do echo "Waiting for database connection..."; sleep 2; done' |
| 80 | + shell: bash |
| 81 | + |
| 82 | + - name: Install dependencies |
| 83 | + run: npm ci |
| 84 | + |
| 85 | + - name: Install Playwright browsers |
| 86 | + run: npx playwright install --with-deps |
| 87 | + if: steps.playwright-cache.outputs.cache-hit != 'true' |
| 88 | + |
| 89 | + - name: Seed database |
| 90 | + run: | |
| 91 | + npm run db:push |
| 92 | + npm run db:seed |
| 93 | +
|
| 94 | + - name: Run Playwright tests |
| 95 | + id: playwright-tests |
| 96 | + run: npx playwright test |
| 97 | + continue-on-error: true |
| 98 | + |
| 99 | + - name: Upload Playwright report |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + if: always() |
| 102 | + with: |
| 103 | + name: playwright-report |
| 104 | + path: playwright-report/ |
| 105 | + retention-days: 30 |
| 106 | + |
| 107 | + - name: Check test results |
| 108 | + if: steps.playwright-tests.outcome == 'failure' |
| 109 | + run: exit 1 |
0 commit comments