reusable-app-prod.yml 9.9 KB

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