reusable-app-prod.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. name: Reusable build and test app for production
  2. on:
  3. workflow_call:
  4. inputs:
  5. node-version:
  6. required: true
  7. type: string
  8. skip-e2e-test:
  9. type: boolean
  10. secrets:
  11. SLACK_WEBHOOK_URL:
  12. required: true
  13. workflow_dispatch:
  14. inputs:
  15. node-version:
  16. required: true
  17. type: string
  18. default: 24.x
  19. skip-e2e-test:
  20. type: boolean
  21. default: false
  22. secrets:
  23. SLACK_WEBHOOK_URL:
  24. required: true
  25. jobs:
  26. build-prod:
  27. runs-on: ubuntu-latest
  28. outputs:
  29. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  30. steps:
  31. - uses: actions/checkout@v4
  32. - uses: pnpm/action-setup@v6
  33. - uses: actions/setup-node@v6
  34. with:
  35. node-version: ${{ inputs.node-version }}
  36. cache: 'pnpm'
  37. - name: Install turbo
  38. run: |
  39. pnpm add turbo --global
  40. - name: Install dependencies
  41. run: |
  42. pnpm install --frozen-lockfile
  43. - name: Build
  44. working-directory: ./apps/app
  45. run: |
  46. turbo run build --env-mode=loose
  47. env:
  48. ANALYZE: 1
  49. - name: Assemble production artifacts
  50. run: bash apps/app/bin/assemble-prod.sh
  51. - name: Check for broken symlinks in .next/node_modules
  52. run: bash apps/app/bin/check-next-symlinks.sh
  53. - name: Archive production files
  54. id: archive-prod-files
  55. run: |
  56. tar -zcf production.tar.gz --exclude ./apps/app/.next/cache \
  57. package.json \
  58. node_modules \
  59. tsconfig.base.json \
  60. apps/app/.next \
  61. apps/app/config \
  62. apps/app/dist \
  63. apps/app/prisma \
  64. apps/app/public \
  65. apps/app/resource \
  66. apps/app/tmp \
  67. apps/app/.env.production* \
  68. apps/app/node_modules \
  69. apps/app/next.config.js \
  70. apps/app/package.json \
  71. apps/app/tsconfig.json
  72. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  73. - name: Upload production files as artifact
  74. uses: actions/upload-artifact@v4
  75. with:
  76. name: Production Files (node${{ inputs.node-version }})
  77. path: ${{ steps.archive-prod-files.outputs.file }}
  78. - name: Upload report as artifact
  79. uses: actions/upload-artifact@v4
  80. with:
  81. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  82. path: |
  83. apps/app/.next/analyze
  84. - name: Slack Notification
  85. uses: weseek/ghaction-slack-notification@master
  86. if: failure()
  87. with:
  88. type: ${{ job.status }}
  89. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  90. channel: '#ci'
  91. isCompactMode: true
  92. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  93. launch-prod:
  94. needs: [build-prod]
  95. runs-on: ubuntu-latest
  96. # The extracted production tarball does not include pnpm-workspace.yaml or
  97. # packages/*, so pnpm v11's pre-run dep status check would trigger a
  98. # `pnpm install` that fails to resolve `workspace:^` references. Skip it.
  99. env:
  100. pnpm_config_verify_deps_before_run: "false"
  101. strategy:
  102. matrix:
  103. mongodb-version: ['6.0', '8.0']
  104. services:
  105. mongodb:
  106. image: mongo:${{ matrix.mongodb-version }}
  107. ports:
  108. - 27017/tcp
  109. steps:
  110. - uses: actions/setup-node@v6
  111. with:
  112. node-version: ${{ inputs.node-version }}
  113. - name: Download production files artifact
  114. uses: actions/download-artifact@v4
  115. with:
  116. name: Production Files (node${{ inputs.node-version }})
  117. - name: Extract production files
  118. run: |
  119. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  120. # Run after extraction so pnpm/action-setup@v6 can read packageManager from package.json
  121. - uses: pnpm/action-setup@v6
  122. - name: Start Elasticsearch with plugins
  123. uses: elastic/elastic-github-actions/elasticsearch@master
  124. with:
  125. stack-version: 9.3.3
  126. plugins: |
  127. analysis-kuromoji
  128. analysis-icu
  129. security-enabled: false
  130. - name: Wait for Elasticsearch to be ready
  131. run: |
  132. curl \
  133. --no-progress-meter \
  134. -X GET \
  135. --retry 60 \
  136. --retry-delay 1 \
  137. --retry-connrefused \
  138. http://localhost:9200/_cluster/health?wait_for_status=green
  139. - name: pnpm run server:ci
  140. working-directory: ./apps/app
  141. run: |
  142. cp config/ci/.env.local.for-ci .env.production.local
  143. pnpm run server:ci
  144. env:
  145. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  146. ELASTICSEARCH_URI: http://localhost:9200/growi
  147. - name: Slack Notification
  148. uses: weseek/ghaction-slack-notification@master
  149. if: failure()
  150. with:
  151. type: ${{ job.status }}
  152. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  153. channel: '#ci'
  154. isCompactMode: true
  155. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  156. prime-playwright-cache:
  157. if: |
  158. github.event_name == 'workflow_dispatch' ||
  159. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  160. runs-on: ubuntu-latest
  161. steps:
  162. - uses: actions/checkout@v4
  163. - uses: pnpm/action-setup@v6
  164. - uses: actions/setup-node@v6
  165. with:
  166. node-version: ${{ inputs.node-version }}
  167. cache: 'pnpm'
  168. - name: Install dependencies
  169. run: |
  170. pnpm install --frozen-lockfile
  171. - name: Cache Playwright browsers
  172. id: playwright-cache
  173. uses: actions/cache@v4
  174. with:
  175. path: ~/.cache/ms-playwright
  176. key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
  177. - name: Install Playwright browsers
  178. if: steps.playwright-cache.outputs.cache-hit != 'true'
  179. run: |
  180. pnpm playwright install
  181. run-playwright:
  182. needs: [build-prod, prime-playwright-cache]
  183. if: |
  184. github.event_name == 'workflow_dispatch' ||
  185. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  186. runs-on: ubuntu-latest
  187. # Playwright spawns `pnpm run server` inside the extracted prod dir via
  188. # GROWI_WEBSERVER_COMMAND. That dir lacks pnpm-workspace.yaml and packages/*,
  189. # so pnpm v11's pre-run dep status check would fail. Skip it.
  190. env:
  191. pnpm_config_verify_deps_before_run: "false"
  192. strategy:
  193. fail-fast: false
  194. matrix:
  195. browser: [chromium, firefox, webkit]
  196. shard: [1/2, 2/2]
  197. mongodb-version: ['6.0', '8.0']
  198. services:
  199. mongodb:
  200. image: mongo:${{ matrix.mongodb-version }}
  201. ports:
  202. - 27017/tcp
  203. steps:
  204. - uses: actions/checkout@v4
  205. - uses: pnpm/action-setup@v6
  206. - uses: actions/setup-node@v6
  207. with:
  208. node-version: ${{ inputs.node-version }}
  209. cache: 'pnpm'
  210. - name: Install dependencies
  211. run: |
  212. pnpm install --frozen-lockfile
  213. # Browsers are pre-populated by `prime-playwright-cache`. Always a cache hit;
  214. # restore-keys provides a partial fallback if the keyed cache was evicted.
  215. - name: Restore Playwright browser cache
  216. uses: actions/cache/restore@v4
  217. with:
  218. path: ~/.cache/ms-playwright
  219. key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
  220. restore-keys: |
  221. playwright-${{ runner.os }}-
  222. # `--with-deps` installs apt system libraries and re-downloads any browser
  223. # that wasn't in the restored cache. With a primed cache, this only runs apt.
  224. - name: Install Playwright system deps and any missing browsers
  225. run: |
  226. pnpm playwright install --with-deps
  227. - name: Start Elasticsearch with plugins
  228. uses: elastic/elastic-github-actions/elasticsearch@master
  229. with:
  230. stack-version: 9.3.3
  231. plugins: |
  232. analysis-kuromoji
  233. analysis-icu
  234. security-enabled: false
  235. - name: Wait for Elasticsearch to be ready
  236. run: |
  237. curl \
  238. --no-progress-meter \
  239. -X GET \
  240. --retry 60 \
  241. --retry-delay 1 \
  242. --retry-connrefused \
  243. http://localhost:9200/_cluster/health?wait_for_status=green
  244. - name: Download production files artifact
  245. uses: actions/download-artifact@v4
  246. with:
  247. name: Production Files (node${{ inputs.node-version }})
  248. - name: Extract production files to isolated directory
  249. run: |
  250. mkdir -p /tmp/growi-prod
  251. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }} -C /tmp/growi-prod
  252. - name: Copy dotenv file for ci
  253. run: |
  254. cat apps/app/config/ci/.env.local.for-ci >> /tmp/growi-prod/apps/app/.env.production.local
  255. # The installer suite is not sharded, so run it once per mongodb-version
  256. # (shard 1/2 only) rather than redundantly in every chromium shard job.
  257. - name: Playwright Run (--project=chromium/installer)
  258. if: ${{ matrix.browser == 'chromium' && matrix.shard == '1/2' }}
  259. working-directory: ./apps/app
  260. run: |
  261. pnpm playwright test --project=chromium/installer
  262. env:
  263. DEBUG: pw:api
  264. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  265. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-playwright-installer
  266. ELASTICSEARCH_URI: http://localhost:9200/growi
  267. # Each `playwright test` run clears blob-report/ when it writes its report
  268. # (the blob reporter empties its output dir), so move this run's blob out to a
  269. # staging dir before the next run wipes it. Prefixing the mongodb-version keeps
  270. # filenames unique once report-playwright flattens every artifact together.
  271. - name: Stash installer blob report
  272. if: ${{ always() && matrix.browser == 'chromium' && matrix.shard == '1/2' }}
  273. run: |
  274. mkdir -p apps/app/all-blobs
  275. for f in apps/app/blob-report/*.zip; do
  276. [ -e "$f" ] || continue
  277. mv "$f" "apps/app/all-blobs/mongo${{ matrix.mongodb-version }}-$(basename "$f")"
  278. done
  279. - name: Copy dotenv file for automatic installation
  280. run: |
  281. cat apps/app/config/ci/.env.local.for-auto-install >> /tmp/growi-prod/apps/app/.env.production.local
  282. - name: Playwright Run
  283. working-directory: ./apps/app
  284. run: |
  285. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  286. env:
  287. DEBUG: pw:api
  288. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  289. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-playwright
  290. ELASTICSEARCH_URI: http://localhost:9200/growi
  291. - name: Stash main blob report
  292. if: always()
  293. run: |
  294. mkdir -p apps/app/all-blobs
  295. for f in apps/app/blob-report/*.zip; do
  296. [ -e "$f" ] || continue
  297. mv "$f" "apps/app/all-blobs/mongo${{ matrix.mongodb-version }}-$(basename "$f")"
  298. done
  299. - name: Copy dotenv file for automatic installation with allowing guest mode
  300. run: |
  301. cat apps/app/config/ci/.env.local.for-auto-install-with-allowing-guest >> /tmp/growi-prod/apps/app/.env.production.local
  302. - name: Playwright Run (--project=${browser}/guest-mode)
  303. working-directory: ./apps/app
  304. run: |
  305. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  306. env:
  307. DEBUG: pw:api
  308. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  309. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-playwright-guest-mode
  310. ELASTICSEARCH_URI: http://localhost:9200/growi
  311. - name: Stash guest-mode blob report
  312. if: always()
  313. run: |
  314. mkdir -p apps/app/all-blobs
  315. for f in apps/app/blob-report/*.zip; do
  316. [ -e "$f" ] || continue
  317. mv "$f" "apps/app/all-blobs/mongo${{ matrix.mongodb-version }}-$(basename "$f")"
  318. done
  319. - name: Generate shard ID
  320. id: shard-id
  321. if: always()
  322. run: |
  323. SHARD_ID=$(echo "${{ matrix.shard }}" | tr '/' '-')
  324. echo "shard_id=${SHARD_ID}" >> $GITHUB_OUTPUT
  325. - name: Upload test results
  326. uses: actions/upload-artifact@v4
  327. if: always()
  328. with:
  329. name: blob-report-${{ matrix.browser }}-mongo${{ matrix.mongodb-version }}-${{ steps.shard-id.outputs.shard_id }}
  330. path: ./apps/app/all-blobs
  331. retention-days: 30
  332. - name: Slack Notification
  333. uses: weseek/ghaction-slack-notification@master
  334. if: failure()
  335. with:
  336. type: ${{ job.status }}
  337. job_name: '*Node CI for growi - run-playwright (${{ matrix.browser }}, MongoDB ${{ matrix.mongodb-version }})*'
  338. channel: '#ci'
  339. isCompactMode: true
  340. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  341. report-playwright:
  342. needs: [run-playwright]
  343. if: always() && needs.run-playwright.result != 'skipped'
  344. runs-on: ubuntu-latest
  345. steps:
  346. - uses: actions/checkout@v4
  347. - uses: pnpm/action-setup@v6
  348. - uses: actions/setup-node@v6
  349. with:
  350. node-version: ${{ inputs.node-version }}
  351. cache: 'pnpm'
  352. - name: Install dependencies
  353. run: |
  354. pnpm install --frozen-lockfile
  355. - name: Download blob reports
  356. uses: actions/download-artifact@v4
  357. with:
  358. pattern: blob-report-*
  359. path: all-blob-reports
  360. merge-multiple: true
  361. - name: Merge into HTML Report
  362. run: |
  363. mkdir -p playwright-report
  364. if [ -z "$(ls all-blob-reports/*.zip all-blob-reports/*.blob 2>/dev/null || true)" ]; then
  365. echo "<html><body><h1>No test results available</h1><p>This could be because tests were skipped or all artifacts were not available.</p></body></html>" > playwright-report/index.html
  366. else
  367. pnpm playwright merge-reports --reporter html all-blob-reports
  368. fi
  369. - name: Upload HTML report
  370. uses: actions/upload-artifact@v4
  371. with:
  372. name: html-report
  373. path: playwright-report
  374. retention-days: 30
  375. - name: Fail if any playwright shard did not succeed
  376. if: needs.run-playwright.result != 'success'
  377. run: |
  378. echo "run-playwright aggregate result: ${{ needs.run-playwright.result }}"
  379. echo "One or more Playwright shards failed or were cancelled. See html-report artifact for details."
  380. exit 1