reusable-app-prod.yml 9.8 KB

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