reusable-app-prod.yml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. workflow_dispatch:
  14. inputs:
  15. node-version:
  16. required: true
  17. type: string
  18. default: 20.x
  19. skip-e2e-test:
  20. type: boolean
  21. default: false
  22. secrets:
  23. SLACK_WEBHOOK_URL:
  24. required: true
  25. jobs:
  26. build-prod:
  27. runs-on: ubuntu-latest
  28. outputs:
  29. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  30. steps:
  31. - uses: actions/checkout@v4
  32. - uses: pnpm/action-setup@v4
  33. - uses: actions/setup-node@v4
  34. with:
  35. node-version: ${{ inputs.node-version }}
  36. cache: 'pnpm'
  37. - name: Install turbo
  38. run: |
  39. pnpm add turbo --global
  40. - name: Install dependencies
  41. run: |
  42. pnpm install --frozen-lockfile
  43. - name: Build
  44. working-directory: ./apps/app
  45. run: |
  46. turbo run build --env-mode=loose
  47. env:
  48. ANALYZE: 1
  49. - name: Assembling all dependencies
  50. run: |
  51. rm -rf out
  52. pnpm deploy out --prod --filter @growi/app
  53. rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
  54. - name: Archive production files
  55. id: archive-prod-files
  56. run: |
  57. tar -zcf production.tar.gz --exclude ./apps/app/.next/cache \
  58. package.json \
  59. apps/app/.next \
  60. apps/app/config \
  61. apps/app/dist \
  62. apps/app/public \
  63. apps/app/resource \
  64. apps/app/tmp \
  65. apps/app/.env.production* \
  66. apps/app/node_modules \
  67. apps/app/package.json
  68. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  69. - name: Upload production files as artifact
  70. uses: actions/upload-artifact@v4
  71. with:
  72. name: Production Files (node${{ inputs.node-version }})
  73. path: ${{ steps.archive-prod-files.outputs.file }}
  74. - name: Upload report as artifact
  75. uses: actions/upload-artifact@v4
  76. with:
  77. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  78. path: |
  79. apps/app/.next/analyze
  80. - name: Slack Notification
  81. uses: weseek/ghaction-slack-notification@master
  82. if: failure()
  83. with:
  84. type: ${{ job.status }}
  85. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  86. channel: '#ci'
  87. isCompactMode: true
  88. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  89. launch-prod:
  90. needs: [build-prod]
  91. runs-on: ubuntu-latest
  92. services:
  93. mongodb:
  94. image: mongo:6.0
  95. ports:
  96. - 27017/tcp
  97. elasticsearch:
  98. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  99. ports:
  100. - 9200/tcp
  101. env:
  102. discovery.type: single-node
  103. steps:
  104. - uses: actions/checkout@v4
  105. - uses: pnpm/action-setup@v4
  106. - uses: actions/setup-node@v4
  107. with:
  108. node-version: ${{ inputs.node-version }}
  109. cache: 'pnpm'
  110. # avoid setup-node cache failure; see: https://github.com/actions/setup-node/issues/1137
  111. - name: Verify PNPM Cache Directory
  112. run: |
  113. PNPM_STORE_PATH="$( pnpm store path --silent )"
  114. [ -d "$PNPM_STORE_PATH" ] || mkdir -vp "$PNPM_STORE_PATH"
  115. - name: Download production files artifact
  116. uses: actions/download-artifact@v4
  117. with:
  118. name: Production Files (node${{ inputs.node-version }})
  119. - name: Extract procution files
  120. run: |
  121. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  122. - name: pnpm run server:ci
  123. working-directory: ./apps/app
  124. run: |
  125. cp config/ci/.env.local.for-ci .env.production.local
  126. pnpm run server:ci
  127. env:
  128. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  129. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  130. - name: Slack Notification
  131. uses: weseek/ghaction-slack-notification@master
  132. if: failure()
  133. with:
  134. type: ${{ job.status }}
  135. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  136. channel: '#ci'
  137. isCompactMode: true
  138. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  139. run-playwright:
  140. needs: [build-prod]
  141. if: |
  142. github.event_name == 'workflow_dispatch' ||
  143. (!inputs.skip-e2e-test && startsWith(github.head_ref, 'mergify/merge-queue/'))
  144. runs-on: ubuntu-latest
  145. container:
  146. # Match the Playwright version
  147. # https://github.com/microsoft/playwright/issues/20010
  148. image: mcr.microsoft.com/playwright:v1.49.1-jammy
  149. strategy:
  150. fail-fast: false
  151. matrix:
  152. browser: [chromium, firefox, webkit]
  153. shard: [1/2, 2/2]
  154. services:
  155. mongodb:
  156. image: mongo:6.0
  157. ports:
  158. - 27017/tcp
  159. elasticsearch:
  160. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  161. ports:
  162. - 9200/tcp
  163. env:
  164. discovery.type: single-node
  165. steps:
  166. - uses: actions/checkout@v4
  167. - uses: pnpm/action-setup@v4
  168. - uses: actions/setup-node@v4
  169. with:
  170. node-version: ${{ inputs.node-version }}
  171. cache: 'pnpm'
  172. - name: Install dependencies
  173. run: |
  174. pnpm install --frozen-lockfile
  175. - name: Install Playwright browsers
  176. run: |
  177. pnpm playwright install --with-deps ${{ matrix.browser }}
  178. - name: Download production files artifact
  179. uses: actions/download-artifact@v4
  180. with:
  181. name: Production Files (node${{ inputs.node-version }})
  182. - name: Extract procution files
  183. run: |
  184. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  185. - name: Copy dotenv file for ci
  186. working-directory: ./apps/app
  187. run: |
  188. cat config/ci/.env.local.for-ci >> .env.production.local
  189. - name: Playwright Run (--project=chromium/installer)
  190. if: ${{ matrix.browser == 'chromium' }}
  191. working-directory: ./apps/app
  192. run: |
  193. pnpm playwright test --project=chromium/installer
  194. env:
  195. DEBUG: pw:api
  196. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  197. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  198. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  199. - name: Copy dotenv file for automatic installation
  200. working-directory: ./apps/app
  201. run: |
  202. cat config/ci/.env.local.for-auto-install >> .env.production.local
  203. - name: Playwright Run
  204. working-directory: ./apps/app
  205. run: |
  206. pnpm playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  207. env:
  208. DEBUG: pw:api
  209. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  210. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  211. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  212. - name: Copy dotenv file for automatic installation with allowing guest mode
  213. working-directory: ./apps/app
  214. run: |
  215. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  216. - name: Playwright Run (--project=${browser}/guest-mode)
  217. working-directory: ./apps/app
  218. run: |
  219. pnpm playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  220. env:
  221. DEBUG: pw:api
  222. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  223. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  224. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  225. - name: Generate shard ID
  226. id: shard-id
  227. if: always()
  228. run: |
  229. SHARD_ID=$(echo "${{ matrix.shard }}" | tr '/' '-')
  230. echo "shard_id=${SHARD_ID}" >> $GITHUB_OUTPUT
  231. - name: Upload test results
  232. uses: actions/upload-artifact@v4
  233. if: always()
  234. with:
  235. name: blob-report-${{ matrix.browser }}-${{ steps.shard-id.outputs.shard_id }}
  236. path: ./apps/app/blob-report
  237. retention-days: 30
  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 }}
  247. report-playwright:
  248. needs: [run-playwright]
  249. if: always() && needs.run-playwright.result != 'skipped'
  250. runs-on: ubuntu-latest
  251. steps:
  252. - uses: actions/checkout@v4
  253. - uses: pnpm/action-setup@v4
  254. - uses: actions/setup-node@v4
  255. with:
  256. node-version: ${{ inputs.node-version }}
  257. cache: 'pnpm'
  258. - name: Install dependencies
  259. run: |
  260. pnpm install --frozen-lockfile
  261. - name: Download blob reports
  262. uses: actions/download-artifact@v4
  263. with:
  264. pattern: blob-report-*
  265. path: all-blob-reports
  266. merge-multiple: true
  267. - name: Merge into HTML Report
  268. run: |
  269. mkdir -p playwright-report
  270. if [ -z "$(ls all-blob-reports/*.zip all-blob-reports/*.blob 2>/dev/null || true)" ]; then
  271. echo "<html><body><h1>No test results available</h1><p>This could be because tests were skipped or all artifacts were not available.</p></body></html>" > playwright-report/index.html
  272. else
  273. pnpm playwright merge-reports --reporter html all-blob-reports
  274. fi
  275. - name: Upload HTML report
  276. uses: actions/upload-artifact@v4
  277. with:
  278. name: html-report
  279. path: playwright-report
  280. retention-days: 30