reusable-app-prod.yml 8.2 KB

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