reusable-app-prod.yml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. with:
  25. version: 9
  26. - uses: actions/setup-node@v4
  27. with:
  28. node-version: ${{ inputs.node-version }}
  29. cache: 'pnpm'
  30. - name: Install turbo
  31. run: |
  32. pnpm add turbo --global
  33. - name: Prune repositories
  34. run: |
  35. turbo prune @growi/app
  36. rm -rf apps packages
  37. mv out/* .
  38. - name: Install dependencies
  39. run: |
  40. pnpm add node-gyp --global
  41. pnpm install --frozen-lockfile
  42. - name: Cache/Restore dist
  43. uses: actions/cache@v4
  44. with:
  45. path: |
  46. **/.turbo
  47. **/dist
  48. **/node_modules/.cache/turbo
  49. ${{ github.workspace }}/apps/app/.next
  50. key: dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.sha }}
  51. restore-keys: |
  52. dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  53. - name: Build
  54. working-directory: ./apps/app
  55. run: |
  56. turbo run build --env-mode=loose
  57. env:
  58. ANALYZE: 1
  59. - name: Archive production files
  60. id: archive-prod-files
  61. run: |
  62. tar -zcf production.tar.gz \
  63. package.json \
  64. apps/app/.next \
  65. apps/app/config \
  66. apps/app/dist \
  67. apps/app/public \
  68. apps/app/resource \
  69. apps/app/tmp \
  70. apps/app/.env.production* \
  71. apps/app/package.json \
  72. packages/*/dist \
  73. packages/*/package.json
  74. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  75. - name: Upload production files as artifact
  76. uses: actions/upload-artifact@v4
  77. with:
  78. name: Production Files (node${{ inputs.node-version }})
  79. path: ${{ steps.archive-prod-files.outputs.file }}
  80. - name: Upload report as artifact
  81. uses: actions/upload-artifact@v4
  82. with:
  83. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  84. path: |
  85. apps/app/.next/analyze/client.html
  86. apps/app/.next/analyze/server.html
  87. - name: Slack Notification
  88. uses: weseek/ghaction-slack-notification@master
  89. if: failure()
  90. with:
  91. type: ${{ job.status }}
  92. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  93. channel: '#ci'
  94. isCompactMode: true
  95. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  96. launch-prod:
  97. needs: [build-prod]
  98. runs-on: ubuntu-latest
  99. services:
  100. mongodb:
  101. image: mongo:6.0
  102. ports:
  103. - 27017/tcp
  104. elasticsearch:
  105. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  106. ports:
  107. - 9200/tcp
  108. env:
  109. discovery.type: single-node
  110. steps:
  111. - uses: actions/checkout@v4
  112. - uses: pnpm/action-setup@v4
  113. with:
  114. version: 9
  115. - uses: actions/setup-node@v4
  116. with:
  117. node-version: ${{ inputs.node-version }}
  118. cache: 'pnpm'
  119. - name: Install turbo
  120. run: |
  121. pnpm add turbo --global
  122. - name: Prune repositories
  123. run: |
  124. turbo prune @growi/app
  125. rm -rf apps packages
  126. mv out/* .
  127. - name: Install dependencies
  128. run: |
  129. pnpm install --prod
  130. - name: Download production files artifact
  131. uses: actions/download-artifact@v4
  132. with:
  133. name: Production Files (node${{ inputs.node-version }})
  134. - name: Extract procution files artifact
  135. run: |
  136. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  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. with:
  182. version: 9
  183. - uses: actions/setup-node@v4
  184. with:
  185. node-version: ${{ inputs.node-version }}
  186. cache: 'pnpm'
  187. - name: Install dependencies
  188. run: |
  189. pnpm add add node-gyp --global
  190. pnpm install --frozen-lockfile
  191. - name: Install Playwright browsers
  192. run: |
  193. pnpm playwright install --with-deps ${{ matrix.browser }}
  194. - name: Download production files artifact
  195. uses: actions/download-artifact@v4
  196. with:
  197. name: Production Files (node${{ inputs.node-version }})
  198. - name: Extract procution files artifact
  199. run: |
  200. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  201. - name: Copy dotenv file for ci
  202. working-directory: ./apps/app
  203. run: |
  204. cat config/ci/.env.local.for-ci >> .env.production.local
  205. - name: Playwright Run (--project=chromium/installer)
  206. if: ${{ matrix.browser == 'chromium' }}
  207. working-directory: ./apps/app
  208. run: |
  209. pnpm playwright test --project=chromium/installer
  210. env:
  211. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  212. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  213. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  214. - name: Copy dotenv file for automatic installation
  215. working-directory: ./apps/app
  216. run: |
  217. cat config/ci/.env.local.for-auto-install >> .env.production.local
  218. - name: Playwright Run
  219. working-directory: ./apps/app
  220. run: |
  221. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  222. env:
  223. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  224. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  225. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  226. - name: Copy dotenv file for automatic installation with allowing guest mode
  227. working-directory: ./apps/app
  228. run: |
  229. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  230. - name: Playwright Run (--project=${browser}/guest-mode)
  231. working-directory: ./apps/app
  232. run: |
  233. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  234. env:
  235. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  236. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  237. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  238. - name: Slack Notification
  239. uses: weseek/ghaction-slack-notification@master
  240. if: failure()
  241. with:
  242. type: ${{ job.status }}
  243. job_name: '*Node CI for growi - run-playwright*'
  244. channel: '#ci'
  245. isCompactMode: true
  246. url: ${{ secrets.SLACK_WEBHOOK_URL }}