e2e.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 8, shard: 1/8 }
  27. - { id: shard-2, name: shard 2 of 8, shard: 2/8 }
  28. - { id: shard-3, name: shard 3 of 8, shard: 3/8 }
  29. - { id: shard-4, name: shard 4 of 8, shard: 4/8 }
  30. - { id: shard-5, name: shard 5 of 8, shard: 5/8 }
  31. - { id: shard-6, name: shard 6 of 8, shard: 6/8 }
  32. - { id: shard-7, name: shard 7 of 8, shard: 7/8 }
  33. - { id: shard-8, name: shard 8 of 8, shard: 8/8 }
  34. # The same build started in cloud mode: plan limits, the sign-up
  35. # pitch and Google sign-in only exist there.
  36. - { id: cloud, name: cloud, mode: cloud }
  37. services:
  38. postgres:
  39. image: postgres:16-alpine
  40. env:
  41. POSTGRES_USER: torqvoice
  42. POSTGRES_PASSWORD: torqvoice
  43. # The name has to carry "e2e" or "test": the harness refuses to reset
  44. # a database whose name says nothing about being throwaway.
  45. POSTGRES_DB: torqvoice_e2e
  46. ports:
  47. - 5432:5432
  48. options: >-
  49. --health-cmd "pg_isready -U torqvoice -d torqvoice_e2e"
  50. --health-interval 10s
  51. --health-timeout 5s
  52. --health-retries 5
  53. env:
  54. # Playwright starts the app itself on this port and resets this database
  55. # before it does; both come from playwright.config.ts.
  56. E2E_DATABASE_URL: postgresql://torqvoice:torqvoice@127.0.0.1:5432/torqvoice_e2e
  57. E2E_MODE: ${{ matrix.mode }}
  58. # The cloud job mints a one-day cloud token from it; without the token the
  59. # app ignores TORQVOICE_MODE=cloud. Only the cloud job gets it.
  60. TORQVOICE_COM_LICENSE_SIGNING_PRIVATE_KEY: ${{ matrix.mode == 'cloud' && secrets.TORQVOICE_COM_LICENSE_SIGNING_PRIVATE_KEY || '' }}
  61. steps:
  62. # A pull request from a fork gets no secrets, so the cloud job has no key
  63. # to mint its cloud token with and the app would refuse cloud mode. That
  64. # says nothing about the contribution, so the job skips instead of failing.
  65. # The self-hosted shards need no key and always run.
  66. - name: Check for the cloud signing key
  67. id: gate
  68. run: |
  69. if [ "${{ matrix.mode }}" = "cloud" ] && [ -z "$TORQVOICE_COM_LICENSE_SIGNING_PRIVATE_KEY" ]; then
  70. echo "::notice title=Cloud specs skipped::No TORQVOICE_COM_LICENSE_SIGNING_PRIVATE_KEY here (a fork or Dependabot pull request), so the cloud specs cannot run."
  71. echo "run=false" >> "$GITHUB_OUTPUT"
  72. else
  73. echo "run=true" >> "$GITHUB_OUTPUT"
  74. fi
  75. - uses: actions/checkout@v4
  76. if: ${{ steps.gate.outputs.run == 'true' }}
  77. - uses: actions/setup-node@v4
  78. if: ${{ steps.gate.outputs.run == 'true' }}
  79. with:
  80. node-version: 22
  81. cache: npm
  82. # A fresh one per run: the sessions it signs live as long as the job, and
  83. # a short or guessable value makes better-auth warn on every request.
  84. - name: Make a session secret for this run
  85. if: ${{ steps.gate.outputs.run == 'true' }}
  86. run: echo "BETTER_AUTH_SECRET=$(openssl rand -base64 32)" >> "$GITHUB_ENV"
  87. - run: npm ci
  88. if: ${{ steps.gate.outputs.run == 'true' }}
  89. - run: npx prisma generate
  90. if: ${{ steps.gate.outputs.run == 'true' }}
  91. # Keyed on the pinned version, because the image tag and this download
  92. # have to be the same build.
  93. - name: Cache the browser
  94. if: ${{ steps.gate.outputs.run == 'true' }}
  95. uses: actions/cache@v4
  96. with:
  97. path: ~/.cache/ms-playwright
  98. key: playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
  99. - name: Install the browser
  100. if: ${{ steps.gate.outputs.run == 'true' }}
  101. run: npx playwright install --with-deps chromium
  102. # The seed copies bundled vehicle photos when they are in the tree and
  103. # downloads fifty of them from Unsplash when they are not, one after
  104. # another, which is minutes of a cold run and the flakiest thing in it.
  105. # Cached, a warm run copies them off disk instead.
  106. - name: Cache the seed's photos
  107. if: ${{ steps.gate.outputs.run == 'true' }}
  108. uses: actions/cache@v4
  109. with:
  110. # Where prepare-db.ts points the seed's DATA_ROOT, so a test run
  111. # cannot disturb a running instance's own uploads.
  112. path: e2e/.data
  113. key: seed-photos-${{ hashFiles('prisma/seed_dummy_data.ts') }}
  114. restore-keys: |
  115. seed-photos-
  116. # Next reuses its compiler cache across builds when it is given one.
  117. # Every job reads it; only the first shard writes it back, so five jobs
  118. # do not race to save the same entry.
  119. - name: Restore the build cache
  120. if: ${{ steps.gate.outputs.run == 'true' }}
  121. uses: actions/cache/restore@v4
  122. with:
  123. path: .next/cache
  124. key: next-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
  125. restore-keys: |
  126. next-${{ hashFiles('package-lock.json') }}-
  127. next-
  128. # NEXT_PUBLIC_APP_URL is baked into the client bundle, and better-auth
  129. # refuses a sign-in from an origin the build was not made for, so it has
  130. # to match the base URL the suite uses.
  131. - name: Build
  132. if: ${{ steps.gate.outputs.run == 'true' }}
  133. run: npm run build
  134. env:
  135. NEXT_PUBLIC_APP_URL: http://127.0.0.1:3100
  136. - name: Save the build cache
  137. if: ${{ steps.gate.outputs.run == 'true' && (matrix.id == 'shard-1') }}
  138. uses: actions/cache/save@v4
  139. with:
  140. path: .next/cache
  141. key: next-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
  142. - name: Run the specs
  143. if: ${{ steps.gate.outputs.run == 'true' }}
  144. run: npx playwright test ${{ matrix.shard && format('--shard={0}', matrix.shard) || '' }}
  145. # The blob carries the results with their traces, screenshots and videos;
  146. # the report job turns every job's blob into one HTML report.
  147. - name: Upload the blob report
  148. if: ${{ steps.gate.outputs.run == 'true' && (!cancelled()) }}
  149. uses: actions/upload-artifact@v4
  150. with:
  151. name: blob-report-${{ matrix.id }}
  152. path: blob-report/
  153. retention-days: 1
  154. if-no-files-found: ignore
  155. report:
  156. # Named as the single job used to be, so a required check keeps its name.
  157. name: Playwright
  158. needs: e2e
  159. if: ${{ !cancelled() }}
  160. runs-on: ubuntu-latest
  161. timeout-minutes: 10
  162. steps:
  163. - uses: actions/checkout@v4
  164. - uses: actions/setup-node@v4
  165. with:
  166. node-version: 22
  167. cache: npm
  168. - run: npm ci
  169. - name: Download the blob reports
  170. uses: actions/download-artifact@v4
  171. with:
  172. pattern: blob-report-*
  173. path: all-blob-reports
  174. # Each job's blob lands in a folder of its own. The merge wants them side
  175. # by side, and two jobs may give their file the same name.
  176. - name: Gather the blobs
  177. run: |
  178. mkdir -p blob-reports
  179. for dir in all-blob-reports/*/; do
  180. [ -d "$dir" ] || continue
  181. job=$(basename "$dir")
  182. for file in "$dir"*.zip; do
  183. [ -e "$file" ] || continue
  184. mv "$file" "blob-reports/${job}-$(basename "$file")"
  185. done
  186. done
  187. ls -la blob-reports
  188. - name: Merge the reports
  189. run: npx playwright merge-reports --reporter html ./blob-reports
  190. - name: Upload the report
  191. uses: actions/upload-artifact@v4
  192. with:
  193. name: playwright-report
  194. path: playwright-report/
  195. retention-days: 7
  196. if-no-files-found: ignore
  197. # Green only when every shard and the cloud specs are.
  198. - name: Every job passed
  199. if: ${{ always() }}
  200. run: |
  201. if [ "${{ needs.e2e.result }}" != "success" ]; then
  202. echo "The e2e jobs finished as: ${{ needs.e2e.result }}"
  203. exit 1
  204. fi