reusable-app-prod.yml 8.3 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. steps:
  19. - uses: actions/checkout@v4
  20. with:
  21. # retrieve local font files
  22. lfs: true
  23. - uses: pnpm/action-setup@v4
  24. - uses: actions/setup-node@v4
  25. with:
  26. node-version: ${{ inputs.node-version }}
  27. cache: 'pnpm'
  28. - name: Install turbo
  29. run: |
  30. pnpm add turbo --global
  31. - name: Prune repositories
  32. run: |
  33. turbo prune @growi/app
  34. rm -rf apps packages
  35. mv out/* .
  36. - name: Install dependencies
  37. # Run pnpm install with `--no-frozen-lockfile` option after `turbo prune` to avoid ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY
  38. run: |
  39. pnpm install --no-frozen-lockfile
  40. - name: Cache/Restore dist
  41. uses: actions/cache@v4
  42. with:
  43. path: |
  44. **/.turbo
  45. **/dist
  46. **/node_modules/.cache/turbo
  47. ${{ github.workspace }}/apps/app/.next
  48. key: dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.sha }}
  49. restore-keys: |
  50. dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  51. - name: Build
  52. working-directory: ./apps/app
  53. run: |
  54. turbo run build --env-mode=loose
  55. env:
  56. ANALYZE: 1
  57. - name: Archive production files
  58. id: archive-prod-files
  59. run: |
  60. tar -zcf production.tar.gz \
  61. package.json \
  62. !apps/app/.next/cache \
  63. apps/app/.next \
  64. apps/app/config \
  65. apps/app/dist \
  66. apps/app/public \
  67. apps/app/resource \
  68. apps/app/tmp \
  69. apps/app/.env.production* \
  70. apps/app/package.json \
  71. packages/*/dist \
  72. packages/*/package.json
  73. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  74. - name: Upload production files as artifact
  75. uses: actions/upload-artifact@v4
  76. with:
  77. name: Production Files (node${{ inputs.node-version }})
  78. path: ${{ steps.archive-prod-files.outputs.file }}
  79. - name: Upload report as artifact
  80. uses: actions/upload-artifact@v4
  81. with:
  82. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  83. path: |
  84. apps/app/.next/analyze/client.html
  85. apps/app/.next/analyze/server.html
  86. - name: Slack Notification
  87. uses: weseek/ghaction-slack-notification@master
  88. if: failure()
  89. with:
  90. type: ${{ job.status }}
  91. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  92. channel: '#ci'
  93. isCompactMode: true
  94. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  95. launch-prod:
  96. needs: [build-prod]
  97. runs-on: ubuntu-latest
  98. services:
  99. mongodb:
  100. image: mongo:6.0
  101. ports:
  102. - 27017/tcp
  103. elasticsearch:
  104. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  105. ports:
  106. - 9200/tcp
  107. env:
  108. discovery.type: single-node
  109. steps:
  110. - uses: actions/checkout@v4
  111. - uses: pnpm/action-setup@v4
  112. - uses: actions/setup-node@v4
  113. with:
  114. node-version: ${{ inputs.node-version }}
  115. cache: 'pnpm'
  116. - name: Install turbo
  117. run: |
  118. pnpm add turbo --global
  119. - name: Prune repositories
  120. run: |
  121. turbo prune @growi/app
  122. rm -rf apps packages
  123. mv out/* .
  124. - name: Install dependencies
  125. # Run pnpm install with `--no-frozen-lockfile` option after `turbo prune` to avoid ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY
  126. run: |
  127. pnpm install --no-frozen-lockfile --prod
  128. - name: Download production files artifact
  129. uses: actions/download-artifact@v4
  130. with:
  131. name: Production Files (node${{ inputs.node-version }})
  132. - name: Extract procution files artifact
  133. run: |
  134. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  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 }}