reusable-app-prod.yml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 \
  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. packages/*/dist \
  71. packages/*/package.json
  72. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  73. - name: Upload production files as artifact
  74. uses: actions/upload-artifact@v4
  75. with:
  76. name: Production Files (node${{ inputs.node-version }})
  77. path: ${{ steps.archive-prod-files.outputs.file }}
  78. - name: Upload report as artifact
  79. uses: actions/upload-artifact@v4
  80. with:
  81. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  82. path: |
  83. apps/app/.next/analyze/client.html
  84. apps/app/.next/analyze/server.html
  85. - name: Slack Notification
  86. uses: weseek/ghaction-slack-notification@master
  87. if: failure()
  88. with:
  89. type: ${{ job.status }}
  90. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  91. channel: '#ci'
  92. isCompactMode: true
  93. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  94. launch-prod:
  95. needs: [build-prod]
  96. runs-on: ubuntu-latest
  97. services:
  98. mongodb:
  99. image: mongo:6.0
  100. ports:
  101. - 27017/tcp
  102. elasticsearch:
  103. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  104. ports:
  105. - 9200/tcp
  106. env:
  107. discovery.type: single-node
  108. steps:
  109. - uses: actions/checkout@v4
  110. - uses: pnpm/action-setup@v4
  111. - uses: actions/setup-node@v4
  112. with:
  113. node-version: ${{ inputs.node-version }}
  114. cache: 'pnpm'
  115. - name: Install turbo
  116. run: |
  117. pnpm add turbo --global
  118. - name: Prune repositories
  119. run: |
  120. turbo prune @growi/app
  121. rm -rf apps packages
  122. mv out/* .
  123. - name: Install dependencies
  124. # Run pnpm install with `--no-frozen-lockfile` option after `turbo prune` to avoid ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY
  125. run: |
  126. pnpm install --no-frozen-lockfile --prod
  127. - name: Download production files artifact
  128. uses: actions/download-artifact@v4
  129. with:
  130. name: Production Files (node${{ inputs.node-version }})
  131. - name: Extract procution files artifact
  132. run: |
  133. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  134. - name: pnpm run server:ci
  135. working-directory: ./apps/app
  136. run: |
  137. cp config/ci/.env.local.for-ci .env.production.local
  138. pnpm run server:ci
  139. env:
  140. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  141. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  142. - name: Slack Notification
  143. uses: weseek/ghaction-slack-notification@master
  144. if: failure()
  145. with:
  146. type: ${{ job.status }}
  147. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  148. channel: '#ci'
  149. isCompactMode: true
  150. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  151. run-playwright:
  152. needs: [build-prod]
  153. if: ${{ !inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/') }}
  154. runs-on: ubuntu-latest
  155. container:
  156. # Match the Playwright version
  157. # https://github.com/microsoft/playwright/issues/20010
  158. image: mcr.microsoft.com/playwright:v1.46.0-jammy
  159. strategy:
  160. fail-fast: false
  161. matrix:
  162. browser: [chromium, firefox, webkit]
  163. shard: [1/2, 2/2]
  164. services:
  165. mongodb:
  166. image: mongo:6.0
  167. ports:
  168. - 27017/tcp
  169. elasticsearch:
  170. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  171. ports:
  172. - 9200/tcp
  173. env:
  174. discovery.type: single-node
  175. steps:
  176. - uses: actions/checkout@v4
  177. - uses: pnpm/action-setup@v4
  178. - uses: actions/setup-node@v4
  179. with:
  180. node-version: ${{ inputs.node-version }}
  181. cache: 'pnpm'
  182. - name: Install dependencies
  183. run: |
  184. pnpm install
  185. - name: Install Playwright browsers
  186. run: |
  187. pnpm playwright install --with-deps ${{ matrix.browser }}
  188. - name: Download production files artifact
  189. uses: actions/download-artifact@v4
  190. with:
  191. name: Production Files (node${{ inputs.node-version }})
  192. - name: Extract procution files artifact
  193. run: |
  194. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  195. - name: Copy dotenv file for ci
  196. working-directory: ./apps/app
  197. run: |
  198. cat config/ci/.env.local.for-ci >> .env.production.local
  199. - name: Playwright Run (--project=chromium/installer)
  200. if: ${{ matrix.browser == 'chromium' }}
  201. working-directory: ./apps/app
  202. run: |
  203. pnpm playwright test --project=chromium/installer
  204. env:
  205. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  206. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  207. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  208. - name: Copy dotenv file for automatic installation
  209. working-directory: ./apps/app
  210. run: |
  211. cat config/ci/.env.local.for-auto-install >> .env.production.local
  212. - name: Playwright Run
  213. working-directory: ./apps/app
  214. run: |
  215. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  216. env:
  217. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  218. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  219. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  220. - name: Copy dotenv file for automatic installation with allowing guest mode
  221. working-directory: ./apps/app
  222. run: |
  223. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  224. - name: Playwright Run (--project=${browser}/guest-mode)
  225. working-directory: ./apps/app
  226. run: |
  227. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  228. env:
  229. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  230. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  231. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  232. - name: Slack Notification
  233. uses: weseek/ghaction-slack-notification@master
  234. if: failure()
  235. with:
  236. type: ${{ job.status }}
  237. job_name: '*Node CI for growi - run-playwright*'
  238. channel: '#ci'
  239. isCompactMode: true
  240. url: ${{ secrets.SLACK_WEBHOOK_URL }}