reusable-app-prod.yml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. if: ${{ !inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/') }}
  136. runs-on: ubuntu-latest
  137. container:
  138. # Match the Playwright version
  139. # https://github.com/microsoft/playwright/issues/20010
  140. image: mcr.microsoft.com/playwright:v1.46.0-jammy
  141. strategy:
  142. fail-fast: false
  143. matrix:
  144. browser: [chromium, firefox, webkit]
  145. shard: [1/2, 2/2]
  146. services:
  147. mongodb:
  148. image: mongo:6.0
  149. ports:
  150. - 27017/tcp
  151. elasticsearch:
  152. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  153. ports:
  154. - 9200/tcp
  155. env:
  156. discovery.type: single-node
  157. steps:
  158. - uses: actions/checkout@v4
  159. - uses: pnpm/action-setup@v4
  160. - uses: actions/setup-node@v4
  161. with:
  162. node-version: ${{ inputs.node-version }}
  163. cache: 'pnpm'
  164. - name: Install dependencies
  165. run: |
  166. pnpm install --frozen-lockfile
  167. - name: Install Playwright browsers
  168. run: |
  169. pnpm playwright install --with-deps ${{ matrix.browser }}
  170. - name: Download production files artifact
  171. uses: actions/download-artifact@v4
  172. with:
  173. name: Production Files (node${{ inputs.node-version }})
  174. - name: Extract procution files
  175. run: |
  176. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  177. - name: Copy dotenv file for ci
  178. working-directory: ./apps/app
  179. run: |
  180. cat config/ci/.env.local.for-ci >> .env.production.local
  181. - name: Playwright Run (--project=chromium/installer)
  182. if: ${{ matrix.browser == 'chromium' }}
  183. working-directory: ./apps/app
  184. run: |
  185. pnpm playwright test --project=chromium/installer
  186. env:
  187. DEBUG: pw:api
  188. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  189. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  190. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  191. - name: Copy dotenv file for automatic installation
  192. working-directory: ./apps/app
  193. run: |
  194. cat config/ci/.env.local.for-auto-install >> .env.production.local
  195. - name: Playwright Run
  196. working-directory: ./apps/app
  197. run: |
  198. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  199. env:
  200. DEBUG: pw:api
  201. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  202. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  203. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  204. - name: Copy dotenv file for automatic installation with allowing guest mode
  205. working-directory: ./apps/app
  206. run: |
  207. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  208. - name: Playwright Run (--project=${browser}/guest-mode)
  209. working-directory: ./apps/app
  210. run: |
  211. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  212. env:
  213. DEBUG: pw:api
  214. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  215. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  216. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  217. - name: Upload test results
  218. if: always()
  219. uses: actions/upload-artifact@v4
  220. with:
  221. name: blob-report-${{ matrix.shard }}
  222. path: blob-report
  223. retention-days: 30
  224. - name: Slack Notification
  225. uses: weseek/ghaction-slack-notification@master
  226. if: failure()
  227. with:
  228. type: ${{ job.status }}
  229. job_name: '*Node CI for growi - run-playwright*'
  230. channel: '#ci'
  231. isCompactMode: true
  232. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  233. report-playwright:
  234. needs: [run-playwright]
  235. runs-on: ubuntu-latest
  236. steps:
  237. - uses: actions/checkout@v4
  238. - uses: pnpm/action-setup@v4
  239. - uses: actions/setup-node@v4
  240. with:
  241. node-version: ${{ inputs.node-version }}
  242. cache: 'pnpm'
  243. - name: Merge into HTML Report
  244. run: pnpm playwright merge-reports --reporter html ./all-blob-reports
  245. - name: Upload HTML report
  246. uses: actions/upload-artifact@v4
  247. with:
  248. name: html-report
  249. path: playwright-report
  250. retention-days: 30