reusable-app-prod.yml 9.9 KB

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