e2e.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. name: End-to-end tests
  2. on:
  3. pull_request:
  4. branches: [main]
  5. workflow_dispatch:
  6. # A second push to the same branch makes the run in flight pointless.
  7. concurrency:
  8. group: e2e-${{ github.ref }}
  9. cancel-in-progress: true
  10. # The suite runs one test at a time against one seeded database, so more
  11. # workers would only trip over each other. More databases do not: resetting
  12. # and seeding one takes about fifteen seconds. So the specs are split across
  13. # shards, each on its own runner with its own database, and the cloud specs
  14. # run beside them. The last job merges what they found into one report and is
  15. # the one check a pull request waits on.
  16. jobs:
  17. e2e:
  18. name: Playwright (${{ matrix.name }})
  19. runs-on: ubuntu-latest
  20. timeout-minutes: 30
  21. strategy:
  22. # A failure in one shard says nothing about the others; let them finish.
  23. fail-fast: false
  24. matrix:
  25. include:
  26. - { id: shard-1, name: shard 1 of 4, shard: 1/4 }
  27. - { id: shard-2, name: shard 2 of 4, shard: 2/4 }
  28. - { id: shard-3, name: shard 3 of 4, shard: 3/4 }
  29. - { id: shard-4, name: shard 4 of 4, shard: 4/4 }
  30. # The same build started in cloud mode: plan limits, the sign-up
  31. # pitch and Google sign-in only exist there.
  32. - { id: cloud, name: cloud, mode: cloud }
  33. services:
  34. postgres:
  35. image: postgres:16-alpine
  36. env:
  37. POSTGRES_USER: torqvoice
  38. POSTGRES_PASSWORD: torqvoice
  39. # The name has to carry "e2e" or "test": the harness refuses to reset
  40. # a database whose name says nothing about being throwaway.
  41. POSTGRES_DB: torqvoice_e2e
  42. ports:
  43. - 5432:5432
  44. options: >-
  45. --health-cmd "pg_isready -U torqvoice -d torqvoice_e2e"
  46. --health-interval 10s
  47. --health-timeout 5s
  48. --health-retries 5
  49. env:
  50. # Playwright starts the app itself on this port and resets this database
  51. # before it does; both come from playwright.config.ts.
  52. E2E_DATABASE_URL: postgresql://torqvoice:torqvoice@127.0.0.1:5432/torqvoice_e2e
  53. E2E_MODE: ${{ matrix.mode }}
  54. steps:
  55. - uses: actions/checkout@v4
  56. - uses: actions/setup-node@v4
  57. with:
  58. node-version: 22
  59. cache: npm
  60. # A fresh one per run: the sessions it signs live as long as the job, and
  61. # a short or guessable value makes better-auth warn on every request.
  62. - name: Make a session secret for this run
  63. run: echo "BETTER_AUTH_SECRET=$(openssl rand -base64 32)" >> "$GITHUB_ENV"
  64. - run: npm ci
  65. - run: npx prisma generate
  66. # Keyed on the pinned version, because the image tag and this download
  67. # have to be the same build.
  68. - name: Cache the browser
  69. uses: actions/cache@v4
  70. with:
  71. path: ~/.cache/ms-playwright
  72. key: playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
  73. - name: Install the browser
  74. run: npx playwright install --with-deps chromium
  75. # The seed copies bundled vehicle photos when they are in the tree and
  76. # downloads fifty of them from Unsplash when they are not, one after
  77. # another, which is minutes of a cold run and the flakiest thing in it.
  78. # Cached, a warm run copies them off disk instead.
  79. - name: Cache the seed's photos
  80. uses: actions/cache@v4
  81. with:
  82. # Where prepare-db.ts points the seed's DATA_ROOT, so a test run
  83. # cannot disturb a running instance's own uploads.
  84. path: e2e/.data
  85. key: seed-photos-${{ hashFiles('prisma/seed_dummy_data.ts') }}
  86. restore-keys: |
  87. seed-photos-
  88. # Next reuses its compiler cache across builds when it is given one.
  89. # Every job reads it; only the first shard writes it back, so five jobs
  90. # do not race to save the same entry.
  91. - name: Restore the build cache
  92. uses: actions/cache/restore@v4
  93. with:
  94. path: .next/cache
  95. key: next-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
  96. restore-keys: |
  97. next-${{ hashFiles('package-lock.json') }}-
  98. next-
  99. # NEXT_PUBLIC_APP_URL is baked into the client bundle, and better-auth
  100. # refuses a sign-in from an origin the build was not made for, so it has
  101. # to match the base URL the suite uses.
  102. - name: Build
  103. run: npm run build
  104. env:
  105. NEXT_PUBLIC_APP_URL: http://127.0.0.1:3100
  106. - name: Save the build cache
  107. if: ${{ matrix.id == 'shard-1' }}
  108. uses: actions/cache/save@v4
  109. with:
  110. path: .next/cache
  111. key: next-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
  112. - name: Run the specs
  113. run: npx playwright test ${{ matrix.shard && format('--shard={0}', matrix.shard) || '' }}
  114. # The blob carries the results with their traces, screenshots and videos;
  115. # the report job turns every job's blob into one HTML report.
  116. - name: Upload the blob report
  117. if: ${{ !cancelled() }}
  118. uses: actions/upload-artifact@v4
  119. with:
  120. name: blob-report-${{ matrix.id }}
  121. path: blob-report/
  122. retention-days: 1
  123. if-no-files-found: ignore
  124. report:
  125. # Named as the single job used to be, so a required check keeps its name.
  126. name: Playwright
  127. needs: e2e
  128. if: ${{ !cancelled() }}
  129. runs-on: ubuntu-latest
  130. timeout-minutes: 10
  131. steps:
  132. - uses: actions/checkout@v4
  133. - uses: actions/setup-node@v4
  134. with:
  135. node-version: 22
  136. cache: npm
  137. - run: npm ci
  138. - name: Download the blob reports
  139. uses: actions/download-artifact@v4
  140. with:
  141. pattern: blob-report-*
  142. path: all-blob-reports
  143. # Each job's blob lands in a folder of its own. The merge wants them side
  144. # by side, and two jobs may give their file the same name.
  145. - name: Gather the blobs
  146. run: |
  147. mkdir -p blob-reports
  148. for dir in all-blob-reports/*/; do
  149. [ -d "$dir" ] || continue
  150. job=$(basename "$dir")
  151. for file in "$dir"*.zip; do
  152. [ -e "$file" ] || continue
  153. mv "$file" "blob-reports/${job}-$(basename "$file")"
  154. done
  155. done
  156. ls -la blob-reports
  157. - name: Merge the reports
  158. run: npx playwright merge-reports --reporter html ./blob-reports
  159. - name: Upload the report
  160. uses: actions/upload-artifact@v4
  161. with:
  162. name: playwright-report
  163. path: playwright-report/
  164. retention-days: 7
  165. if-no-files-found: ignore
  166. # Green only when every shard and the cloud specs are.
  167. - name: Every job passed
  168. if: ${{ always() }}
  169. run: |
  170. if [ "${{ needs.e2e.result }}" != "success" ]; then
  171. echo "The e2e jobs finished as: ${{ needs.e2e.result }}"
  172. exit 1
  173. fi