reusable-app-prod.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. name: Reusable build app workflow 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: 20.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: Cache/Restore dist
  44. uses: actions/cache@v4
  45. with:
  46. path: |
  47. **/.turbo
  48. **/dist
  49. **/node_modules/.cache/turbo
  50. ${{ github.workspace }}/apps/app/.next
  51. key: dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.sha }}
  52. restore-keys: |
  53. dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  54. - name: Build
  55. working-directory: ./apps/app
  56. run: |
  57. turbo run build --env-mode=loose
  58. env:
  59. ANALYZE: 1
  60. - name: Assembling all dependencies
  61. run: |
  62. rm -rf out
  63. pnpm deploy out --prod --filter @growi/app
  64. rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
  65. - name: Archive production files
  66. id: archive-prod-files
  67. run: |
  68. tar -zcf production.tar.gz --exclude ./apps/app/.next/cache \
  69. package.json \
  70. apps/app/.next \
  71. apps/app/config \
  72. apps/app/dist \
  73. apps/app/public \
  74. apps/app/resource \
  75. apps/app/tmp \
  76. apps/app/.env.production* \
  77. apps/app/node_modules \
  78. apps/app/package.json
  79. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  80. - name: Upload production files as artifact
  81. uses: actions/upload-artifact@v4
  82. with:
  83. name: Production Files (node${{ inputs.node-version }})
  84. path: ${{ steps.archive-prod-files.outputs.file }}
  85. - name: Upload report as artifact
  86. uses: actions/upload-artifact@v4
  87. with:
  88. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  89. path: |
  90. apps/app/.next/analyze
  91. - name: Slack Notification
  92. uses: weseek/ghaction-slack-notification@master
  93. if: failure()
  94. with:
  95. type: ${{ job.status }}
  96. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  97. channel: '#ci'
  98. isCompactMode: true
  99. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  100. launch-prod:
  101. needs: [build-prod]
  102. runs-on: ubuntu-latest
  103. services:
  104. mongodb:
  105. image: mongo:6.0
  106. ports:
  107. - 27017/tcp
  108. elasticsearch:
  109. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  110. ports:
  111. - 9200/tcp
  112. env:
  113. discovery.type: single-node
  114. steps:
  115. - uses: actions/checkout@v4
  116. - uses: pnpm/action-setup@v4
  117. - uses: actions/setup-node@v4
  118. with:
  119. node-version: ${{ inputs.node-version }}
  120. cache: 'pnpm'
  121. - name: Download production files artifact
  122. uses: actions/download-artifact@v4
  123. with:
  124. name: Production Files (node${{ inputs.node-version }})
  125. - name: Extract procution files
  126. run: |
  127. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  128. - name: pnpm run server:ci
  129. working-directory: ./apps/app
  130. run: |
  131. cp config/ci/.env.local.for-ci .env.production.local
  132. pnpm run server:ci
  133. env:
  134. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  135. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  136. - name: Slack Notification
  137. uses: weseek/ghaction-slack-notification@master
  138. if: failure()
  139. with:
  140. type: ${{ job.status }}
  141. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  142. channel: '#ci'
  143. isCompactMode: true
  144. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  145. run-playwright:
  146. needs: [build-prod]
  147. if: |
  148. github.event_name == 'workflow_dispatch' ||
  149. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  150. runs-on: ubuntu-latest
  151. container:
  152. # Match the Playwright version
  153. # https://github.com/microsoft/playwright/issues/20010
  154. image: mcr.microsoft.com/playwright:v1.46.0-jammy
  155. strategy:
  156. fail-fast: false
  157. matrix:
  158. browser: [chromium, firefox, webkit]
  159. shard: [1/2, 2/2]
  160. services:
  161. mongodb:
  162. image: mongo:6.0
  163. ports:
  164. - 27017/tcp
  165. elasticsearch:
  166. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  167. ports:
  168. - 9200/tcp
  169. env:
  170. discovery.type: single-node
  171. steps:
  172. - uses: actions/checkout@v4
  173. - uses: pnpm/action-setup@v4
  174. - uses: actions/setup-node@v4
  175. with:
  176. node-version: ${{ inputs.node-version }}
  177. cache: 'pnpm'
  178. - name: Install dependencies
  179. run: |
  180. pnpm install --frozen-lockfile
  181. - name: Install Playwright browsers
  182. run: |
  183. pnpm playwright install --with-deps ${{ matrix.browser }}
  184. - name: Download production files artifact
  185. uses: actions/download-artifact@v4
  186. with:
  187. name: Production Files (node${{ inputs.node-version }})
  188. - name: Extract procution files
  189. run: |
  190. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  191. - name: Copy dotenv file for ci
  192. working-directory: ./apps/app
  193. run: |
  194. cat config/ci/.env.local.for-ci >> .env.production.local
  195. - name: Playwright Run (--project=chromium/installer)
  196. if: ${{ matrix.browser == 'chromium' }}
  197. working-directory: ./apps/app
  198. run: |
  199. pnpm playwright test --project=chromium/installer
  200. env:
  201. DEBUG: pw:api
  202. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  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. working-directory: ./apps/app
  207. run: |
  208. cat config/ci/.env.local.for-auto-install >> .env.production.local
  209. - name: Playwright Run
  210. working-directory: ./apps/app
  211. run: |
  212. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  213. env:
  214. DEBUG: pw:api
  215. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  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. working-directory: ./apps/app
  220. run: |
  221. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  222. - name: Playwright Run (--project=${browser}/guest-mode)
  223. working-directory: ./apps/app
  224. run: |
  225. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  226. env:
  227. DEBUG: pw:api
  228. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  229. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  230. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  231. - name: Upload test results
  232. if: always()
  233. uses: actions/upload-artifact@v4
  234. with:
  235. name: blob-report-${{ matrix.shard }}
  236. path: 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*'
  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: Merge into HTML Report
  262. run: pnpm playwright merge-reports --reporter html ./all-blob-reports
  263. - name: Upload HTML report
  264. uses: actions/upload-artifact@v4
  265. with:
  266. name: html-report
  267. path: playwright-report
  268. retention-days: 30