reusable-app-prod.yml 9.2 KB

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