reusable-app-prod.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. - name: pnpm run server:ci
  136. working-directory: ./apps/app
  137. run: |
  138. cp config/ci/.env.local.for-ci .env.production.local
  139. pnpm run server:ci
  140. env:
  141. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  142. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  143. - name: Slack Notification
  144. uses: weseek/ghaction-slack-notification@master
  145. if: failure()
  146. with:
  147. type: ${{ job.status }}
  148. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  149. channel: '#ci'
  150. isCompactMode: true
  151. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  152. run-playwright:
  153. needs: [build-prod]
  154. if: ${{ !inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/') }}
  155. runs-on: ubuntu-latest
  156. container:
  157. # Match the Playwright version
  158. # https://github.com/microsoft/playwright/issues/20010
  159. image: mcr.microsoft.com/playwright:v1.46.0-jammy
  160. strategy:
  161. fail-fast: false
  162. matrix:
  163. browser: [chromium, firefox, webkit]
  164. shard: [1/2, 2/2]
  165. services:
  166. mongodb:
  167. image: mongo:6.0
  168. ports:
  169. - 27017/tcp
  170. elasticsearch:
  171. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  172. ports:
  173. - 9200/tcp
  174. env:
  175. discovery.type: single-node
  176. steps:
  177. - uses: actions/checkout@v4
  178. - uses: pnpm/action-setup@v4
  179. - uses: actions/setup-node@v4
  180. with:
  181. node-version: ${{ inputs.node-version }}
  182. cache: 'pnpm'
  183. - name: Install dependencies
  184. run: |
  185. pnpm install
  186. - name: Install Playwright browsers
  187. run: |
  188. pnpm playwright install --with-deps ${{ matrix.browser }}
  189. - name: Download production files artifact
  190. uses: actions/download-artifact@v4
  191. with:
  192. name: Production Files (node${{ inputs.node-version }})
  193. - name: Extract procution files artifact
  194. run: |
  195. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  196. - name: Copy dotenv file for ci
  197. working-directory: ./apps/app
  198. run: |
  199. cat config/ci/.env.local.for-ci >> .env.production.local
  200. - name: Playwright Run (--project=chromium/installer)
  201. if: ${{ matrix.browser == 'chromium' }}
  202. working-directory: ./apps/app
  203. run: |
  204. pnpm playwright test --project=chromium/installer
  205. env:
  206. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  207. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  208. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  209. - name: Copy dotenv file for automatic installation
  210. working-directory: ./apps/app
  211. run: |
  212. cat config/ci/.env.local.for-auto-install >> .env.production.local
  213. - name: Playwright Run
  214. working-directory: ./apps/app
  215. run: |
  216. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  217. env:
  218. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  219. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  220. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  221. - name: Copy dotenv file for automatic installation with allowing guest mode
  222. working-directory: ./apps/app
  223. run: |
  224. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  225. - name: Playwright Run (--project=${browser}/guest-mode)
  226. working-directory: ./apps/app
  227. run: |
  228. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  229. env:
  230. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  231. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  232. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  233. - name: Slack Notification
  234. uses: weseek/ghaction-slack-notification@master
  235. if: failure()
  236. with:
  237. type: ${{ job.status }}
  238. job_name: '*Node CI for growi - run-playwright*'
  239. channel: '#ci'
  240. isCompactMode: true
  241. url: ${{ secrets.SLACK_WEBHOOK_URL }}