reusable-app-prod.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. - uses: pnpm/action-setup@v4
  21. - uses: actions/setup-node@v4
  22. with:
  23. node-version: ${{ inputs.node-version }}
  24. cache: 'pnpm'
  25. - name: Install turbo
  26. run: |
  27. pnpm add turbo --global
  28. - name: Install dependencies
  29. run: |
  30. pnpm install --frozen-lockfile
  31. - name: Cache/Restore dist
  32. uses: actions/cache@v4
  33. with:
  34. path: |
  35. **/.turbo
  36. **/dist
  37. **/node_modules/.cache/turbo
  38. ${{ github.workspace }}/apps/app/.next
  39. key: dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.sha }}
  40. restore-keys: |
  41. dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  42. - name: Build
  43. working-directory: ./apps/app
  44. run: |
  45. turbo run build --env-mode=loose
  46. env:
  47. ANALYZE: 1
  48. - name: Assembling all dependencies
  49. run: |
  50. rm -rf out
  51. pnpm deploy out --prod --filter @growi/app
  52. rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
  53. - name: Archive production files
  54. id: archive-prod-files
  55. run: |
  56. tar -zcf production.tar.gz --exclude ./apps/app/.next/cache \
  57. package.json \
  58. apps/app/.next \
  59. apps/app/config \
  60. apps/app/dist \
  61. apps/app/public \
  62. apps/app/resource \
  63. apps/app/tmp \
  64. apps/app/.env.production* \
  65. apps/app/node_modules \
  66. apps/app/package.json
  67. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  68. - name: Upload production files as artifact
  69. uses: actions/upload-artifact@v4
  70. with:
  71. name: Production Files (node${{ inputs.node-version }})
  72. path: ${{ steps.archive-prod-files.outputs.file }}
  73. - name: Upload report as artifact
  74. uses: actions/upload-artifact@v4
  75. with:
  76. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  77. path: |
  78. apps/app/.next/analyze
  79. - name: Slack Notification
  80. uses: weseek/ghaction-slack-notification@master
  81. if: failure()
  82. with:
  83. type: ${{ job.status }}
  84. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  85. channel: '#ci'
  86. isCompactMode: true
  87. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  88. launch-prod:
  89. needs: [build-prod]
  90. runs-on: ubuntu-latest
  91. services:
  92. mongodb:
  93. image: mongo:6.0
  94. ports:
  95. - 27017/tcp
  96. elasticsearch:
  97. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  98. ports:
  99. - 9200/tcp
  100. env:
  101. discovery.type: single-node
  102. steps:
  103. - uses: actions/checkout@v4
  104. - uses: pnpm/action-setup@v4
  105. - uses: actions/setup-node@v4
  106. with:
  107. node-version: ${{ inputs.node-version }}
  108. cache: 'pnpm'
  109. - name: Download production files artifact
  110. uses: actions/download-artifact@v4
  111. with:
  112. name: Production Files (node${{ inputs.node-version }})
  113. - name: Extract procution files
  114. run: |
  115. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  116. - name: pnpm run server:ci
  117. working-directory: ./apps/app
  118. run: |
  119. cp config/ci/.env.local.for-ci .env.production.local
  120. pnpm run server:ci
  121. env:
  122. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  123. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  124. - name: Slack Notification
  125. uses: weseek/ghaction-slack-notification@master
  126. if: failure()
  127. with:
  128. type: ${{ job.status }}
  129. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  130. channel: '#ci'
  131. isCompactMode: true
  132. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  133. run-playwright:
  134. needs: [build-prod]
  135. runs-on: ubuntu-latest
  136. container:
  137. # Match the Playwright version
  138. # https://github.com/microsoft/playwright/issues/20010
  139. image: mcr.microsoft.com/playwright:v1.46.0-jammy
  140. strategy:
  141. fail-fast: false
  142. matrix:
  143. browser: [chromium, firefox, webkit]
  144. shard: [1/2, 2/2]
  145. services:
  146. mongodb:
  147. image: mongo:6.0
  148. ports:
  149. - 27017/tcp
  150. elasticsearch:
  151. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  152. ports:
  153. - 9200/tcp
  154. env:
  155. discovery.type: single-node
  156. steps:
  157. - uses: actions/checkout@v4
  158. - uses: pnpm/action-setup@v4
  159. - uses: actions/setup-node@v4
  160. with:
  161. node-version: ${{ inputs.node-version }}
  162. cache: 'pnpm'
  163. - name: Install dependencies
  164. run: |
  165. pnpm install --frozen-lockfile
  166. - name: Install Playwright browsers
  167. run: |
  168. pnpm playwright install --with-deps ${{ matrix.browser }}
  169. - name: Download production files artifact
  170. uses: actions/download-artifact@v4
  171. with:
  172. name: Production Files (node${{ inputs.node-version }})
  173. - name: Extract procution files
  174. run: |
  175. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  176. - name: Copy dotenv file for ci
  177. working-directory: ./apps/app
  178. run: |
  179. cat config/ci/.env.local.for-ci >> .env.production.local
  180. - name: Playwright Run (--project=chromium/installer)
  181. if: ${{ matrix.browser == 'chromium' }}
  182. working-directory: ./apps/app
  183. run: |
  184. pnpm playwright test --project=chromium/installer
  185. env:
  186. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  187. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  188. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  189. - name: Copy dotenv file for automatic installation
  190. working-directory: ./apps/app
  191. run: |
  192. cat config/ci/.env.local.for-auto-install >> .env.production.local
  193. - name: Playwright Run
  194. working-directory: ./apps/app
  195. run: |
  196. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  197. env:
  198. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  199. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  200. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  201. - name: Copy dotenv file for automatic installation with allowing guest mode
  202. working-directory: ./apps/app
  203. run: |
  204. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  205. - name: Playwright Run (--project=${browser}/guest-mode)
  206. working-directory: ./apps/app
  207. run: |
  208. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  209. env:
  210. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  211. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  212. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  213. - name: Slack Notification
  214. uses: weseek/ghaction-slack-notification@master
  215. if: failure()
  216. with:
  217. type: ${{ job.status }}
  218. job_name: '*Node CI for growi - run-playwright*'
  219. channel: '#ci'
  220. isCompactMode: true
  221. url: ${{ secrets.SLACK_WEBHOOK_URL }}