reusable-app-prod.yml 10 KB

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