reusable-app-prod.yml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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@v4
  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. apps/app/.next \
  60. apps/app/config \
  61. apps/app/dist \
  62. apps/app/public \
  63. apps/app/resource \
  64. apps/app/tmp \
  65. apps/app/.env.production* \
  66. apps/app/node_modules \
  67. apps/app/next.config.js \
  68. apps/app/package.json
  69. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  70. - name: Upload production files as artifact
  71. uses: actions/upload-artifact@v4
  72. with:
  73. name: Production Files (node${{ inputs.node-version }})
  74. path: ${{ steps.archive-prod-files.outputs.file }}
  75. - name: Upload report as artifact
  76. uses: actions/upload-artifact@v4
  77. with:
  78. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  79. path: |
  80. apps/app/.next/analyze
  81. - name: Slack Notification
  82. uses: weseek/ghaction-slack-notification@master
  83. if: failure()
  84. with:
  85. type: ${{ job.status }}
  86. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  87. channel: '#ci'
  88. isCompactMode: true
  89. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  90. launch-prod:
  91. needs: [build-prod]
  92. runs-on: ubuntu-latest
  93. strategy:
  94. matrix:
  95. mongodb-version: ['6.0', '8.0']
  96. services:
  97. mongodb:
  98. image: mongo:${{ matrix.mongodb-version }}
  99. ports:
  100. - 27017/tcp
  101. elasticsearch:
  102. image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
  103. ports:
  104. - 9200/tcp
  105. env:
  106. discovery.type: single-node
  107. steps:
  108. - uses: actions/setup-node@v4
  109. with:
  110. node-version: ${{ inputs.node-version }}
  111. - name: Download production files artifact
  112. uses: actions/download-artifact@v4
  113. with:
  114. name: Production Files (node${{ inputs.node-version }})
  115. - name: Extract production files
  116. run: |
  117. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  118. # Run after extraction so pnpm/action-setup@v4 can read packageManager from package.json
  119. - uses: pnpm/action-setup@v4
  120. - name: pnpm run server:ci
  121. working-directory: ./apps/app
  122. run: |
  123. cp config/ci/.env.local.for-ci .env.production.local
  124. pnpm run server:ci
  125. env:
  126. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  127. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  128. - name: Slack Notification
  129. uses: weseek/ghaction-slack-notification@master
  130. if: failure()
  131. with:
  132. type: ${{ job.status }}
  133. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  134. channel: '#ci'
  135. isCompactMode: true
  136. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  137. run-playwright:
  138. needs: [build-prod]
  139. if: |
  140. github.event_name == 'workflow_dispatch' ||
  141. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  142. runs-on: ubuntu-latest
  143. container:
  144. # Match the Playwright version
  145. # https://github.com/microsoft/playwright/issues/20010
  146. image: mcr.microsoft.com/playwright:v1.58.2-jammy
  147. strategy:
  148. fail-fast: false
  149. matrix:
  150. browser: [chromium, firefox, webkit]
  151. shard: [1/2, 2/2]
  152. mongodb-version: ['6.0', '8.0']
  153. services:
  154. mongodb:
  155. image: mongo:${{ matrix.mongodb-version }}
  156. ports:
  157. - 27017/tcp
  158. elasticsearch:
  159. image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
  160. ports:
  161. - 9200/tcp
  162. env:
  163. discovery.type: single-node
  164. steps:
  165. - uses: actions/checkout@v4
  166. - uses: pnpm/action-setup@v4
  167. - uses: actions/setup-node@v4
  168. with:
  169. node-version: ${{ inputs.node-version }}
  170. cache: 'pnpm'
  171. - name: Install dependencies
  172. run: |
  173. pnpm install --frozen-lockfile
  174. - name: Install Playwright browsers
  175. run: |
  176. pnpm playwright install --with-deps ${{ matrix.browser }}
  177. - name: Download production files artifact
  178. uses: actions/download-artifact@v4
  179. with:
  180. name: Production Files (node${{ inputs.node-version }})
  181. - name: Extract production files to isolated directory
  182. run: |
  183. mkdir -p /tmp/growi-prod
  184. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }} -C /tmp/growi-prod
  185. - name: Copy dotenv file for ci
  186. run: |
  187. cat apps/app/config/ci/.env.local.for-ci >> /tmp/growi-prod/apps/app/.env.production.local
  188. - name: Playwright Run (--project=chromium/installer)
  189. if: ${{ matrix.browser == 'chromium' }}
  190. working-directory: ./apps/app
  191. run: |
  192. pnpm playwright test --project=chromium/installer
  193. env:
  194. DEBUG: pw:api
  195. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  196. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  197. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  198. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  199. - name: Copy dotenv file for automatic installation
  200. run: |
  201. cat apps/app/config/ci/.env.local.for-auto-install >> /tmp/growi-prod/apps/app/.env.production.local
  202. - name: Playwright Run
  203. working-directory: ./apps/app
  204. run: |
  205. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  206. env:
  207. DEBUG: pw:api
  208. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  209. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  210. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  211. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  212. - name: Copy dotenv file for automatic installation with allowing guest mode
  213. run: |
  214. cat apps/app/config/ci/.env.local.for-auto-install-with-allowing-guest >> /tmp/growi-prod/apps/app/.env.production.local
  215. - name: Playwright Run (--project=${browser}/guest-mode)
  216. working-directory: ./apps/app
  217. run: |
  218. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  219. env:
  220. DEBUG: pw:api
  221. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  222. GROWI_WEBSERVER_COMMAND: 'cd /tmp/growi-prod/apps/app && pnpm run server'
  223. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  224. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  225. - name: Generate shard ID
  226. id: shard-id
  227. if: always()
  228. run: |
  229. SHARD_ID=$(echo "${{ matrix.shard }}" | tr '/' '-')
  230. echo "shard_id=${SHARD_ID}" >> $GITHUB_OUTPUT
  231. - name: Upload test results
  232. uses: actions/upload-artifact@v4
  233. if: always()
  234. with:
  235. name: blob-report-${{ matrix.browser }}-mongo${{ matrix.mongodb-version }}-${{ steps.shard-id.outputs.shard_id }}
  236. path: ./apps/app/blob-report
  237. retention-days: 30
  238. - name: Slack Notification
  239. uses: weseek/ghaction-slack-notification@master
  240. if: failure()
  241. with:
  242. type: ${{ job.status }}
  243. job_name: '*Node CI for growi - run-playwright (${{ matrix.browser }}, MongoDB ${{ matrix.mongodb-version }})*'
  244. channel: '#ci'
  245. isCompactMode: true
  246. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  247. report-playwright:
  248. needs: [run-playwright]
  249. if: always() && needs.run-playwright.result != 'skipped'
  250. runs-on: ubuntu-latest
  251. steps:
  252. - uses: actions/checkout@v4
  253. - uses: pnpm/action-setup@v4
  254. - uses: actions/setup-node@v4
  255. with:
  256. node-version: ${{ inputs.node-version }}
  257. cache: 'pnpm'
  258. - name: Install dependencies
  259. run: |
  260. pnpm install --frozen-lockfile
  261. - name: Download blob reports
  262. uses: actions/download-artifact@v4
  263. with:
  264. pattern: blob-report-*
  265. path: all-blob-reports
  266. merge-multiple: true
  267. - name: Merge into HTML Report
  268. run: |
  269. mkdir -p playwright-report
  270. if [ -z "$(ls all-blob-reports/*.zip all-blob-reports/*.blob 2>/dev/null || true)" ]; then
  271. 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
  272. else
  273. pnpm playwright merge-reports --reporter html all-blob-reports
  274. fi
  275. - name: Upload HTML report
  276. uses: actions/upload-artifact@v4
  277. with:
  278. name: html-report
  279. path: playwright-report
  280. retention-days: 30