reusable-app-prod.yml 8.5 KB

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