reusable-app-prod.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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@v4
  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. elasticsearch:
  110. image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
  111. ports:
  112. - 9200/tcp
  113. env:
  114. discovery.type: single-node
  115. # ES 9.x enables security (HTTPS + auth) by default; disable for plaintext CI access
  116. xpack.security.enabled: false
  117. steps:
  118. - uses: actions/setup-node@v4
  119. with:
  120. node-version: ${{ inputs.node-version }}
  121. - name: Download production files artifact
  122. uses: actions/download-artifact@v4
  123. with:
  124. name: Production Files (node${{ inputs.node-version }})
  125. - name: Extract production files
  126. run: |
  127. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  128. # Run after extraction so pnpm/action-setup@v6 can read packageManager from package.json
  129. - uses: pnpm/action-setup@v6
  130. - name: pnpm run server:ci
  131. working-directory: ./apps/app
  132. run: |
  133. cp config/ci/.env.local.for-ci .env.production.local
  134. pnpm run server:ci
  135. env:
  136. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  137. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  138. - name: Slack Notification
  139. uses: weseek/ghaction-slack-notification@master
  140. if: failure()
  141. with:
  142. type: ${{ job.status }}
  143. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  144. channel: '#ci'
  145. isCompactMode: true
  146. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  147. run-playwright:
  148. needs: [build-prod]
  149. if: |
  150. github.event_name == 'workflow_dispatch' ||
  151. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  152. runs-on: ubuntu-latest
  153. container:
  154. # Match the Playwright version
  155. # https://github.com/microsoft/playwright/issues/20010
  156. image: mcr.microsoft.com/playwright:v1.58.2-jammy
  157. # Playwright spawns `pnpm run server` inside the extracted prod dir via
  158. # GROWI_WEBSERVER_COMMAND. That dir lacks pnpm-workspace.yaml and packages/*,
  159. # so pnpm v11's pre-run dep status check would fail. Skip it.
  160. env:
  161. pnpm_config_verify_deps_before_run: "false"
  162. strategy:
  163. fail-fast: false
  164. matrix:
  165. browser: [chromium, firefox, webkit]
  166. shard: [1/2, 2/2]
  167. mongodb-version: ['6.0', '8.0']
  168. services:
  169. mongodb:
  170. image: mongo:${{ matrix.mongodb-version }}
  171. ports:
  172. - 27017/tcp
  173. elasticsearch:
  174. image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
  175. ports:
  176. - 9200/tcp
  177. env:
  178. discovery.type: single-node
  179. # ES 9.x enables security (HTTPS + auth) by default; disable for plaintext CI access
  180. xpack.security.enabled: false
  181. steps:
  182. - uses: actions/checkout@v4
  183. - uses: pnpm/action-setup@v6
  184. - uses: actions/setup-node@v4
  185. with:
  186. node-version: ${{ inputs.node-version }}
  187. cache: 'pnpm'
  188. - name: Install dependencies
  189. run: |
  190. pnpm install --frozen-lockfile
  191. - name: Install Playwright browsers
  192. run: |
  193. pnpm playwright install --with-deps ${{ matrix.browser }}
  194. - name: Download production files artifact
  195. uses: actions/download-artifact@v4
  196. with:
  197. name: Production Files (node${{ inputs.node-version }})
  198. - name: Extract production files to isolated directory
  199. run: |
  200. mkdir -p /tmp/growi-prod
  201. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }} -C /tmp/growi-prod
  202. - name: Copy dotenv file for ci
  203. run: |
  204. cat apps/app/config/ci/.env.local.for-ci >> /tmp/growi-prod/apps/app/.env.production.local
  205. - name: Playwright Run (--project=chromium/installer)
  206. if: ${{ matrix.browser == 'chromium' }}
  207. working-directory: ./apps/app
  208. run: |
  209. pnpm playwright test --project=chromium/installer
  210. env:
  211. DEBUG: pw:api
  212. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  213. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  214. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  215. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  216. - name: Copy dotenv file for automatic installation
  217. run: |
  218. cat apps/app/config/ci/.env.local.for-auto-install >> /tmp/growi-prod/apps/app/.env.production.local
  219. - name: Playwright Run
  220. working-directory: ./apps/app
  221. run: |
  222. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  223. env:
  224. DEBUG: pw:api
  225. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  226. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  227. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  228. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  229. - name: Copy dotenv file for automatic installation with allowing guest mode
  230. run: |
  231. cat apps/app/config/ci/.env.local.for-auto-install-with-allowing-guest >> /tmp/growi-prod/apps/app/.env.production.local
  232. - name: Playwright Run (--project=${browser}/guest-mode)
  233. working-directory: ./apps/app
  234. run: |
  235. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  236. env:
  237. DEBUG: pw:api
  238. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  239. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  240. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  241. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  242. - name: Generate shard ID
  243. id: shard-id
  244. if: always()
  245. run: |
  246. SHARD_ID=$(echo "${{ matrix.shard }}" | tr '/' '-')
  247. echo "shard_id=${SHARD_ID}" >> $GITHUB_OUTPUT
  248. - name: Upload test results
  249. uses: actions/upload-artifact@v4
  250. if: always()
  251. with:
  252. name: blob-report-${{ matrix.browser }}-mongo${{ matrix.mongodb-version }}-${{ steps.shard-id.outputs.shard_id }}
  253. path: ./apps/app/blob-report
  254. retention-days: 30
  255. - name: Slack Notification
  256. uses: weseek/ghaction-slack-notification@master
  257. if: failure()
  258. with:
  259. type: ${{ job.status }}
  260. job_name: '*Node CI for growi - run-playwright (${{ matrix.browser }}, MongoDB ${{ matrix.mongodb-version }})*'
  261. channel: '#ci'
  262. isCompactMode: true
  263. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  264. report-playwright:
  265. needs: [run-playwright]
  266. if: always() && needs.run-playwright.result != 'skipped'
  267. runs-on: ubuntu-latest
  268. steps:
  269. - uses: actions/checkout@v4
  270. - uses: pnpm/action-setup@v6
  271. - uses: actions/setup-node@v4
  272. with:
  273. node-version: ${{ inputs.node-version }}
  274. cache: 'pnpm'
  275. - name: Install dependencies
  276. run: |
  277. pnpm install --frozen-lockfile
  278. - name: Download blob reports
  279. uses: actions/download-artifact@v4
  280. with:
  281. pattern: blob-report-*
  282. path: all-blob-reports
  283. merge-multiple: true
  284. - name: Merge into HTML Report
  285. run: |
  286. mkdir -p playwright-report
  287. if [ -z "$(ls all-blob-reports/*.zip all-blob-reports/*.blob 2>/dev/null || true)" ]; then
  288. 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
  289. else
  290. pnpm playwright merge-reports --reporter html all-blob-reports
  291. fi
  292. - name: Upload HTML report
  293. uses: actions/upload-artifact@v4
  294. with:
  295. name: html-report
  296. path: playwright-report
  297. retention-days: 30