reusable-app-prod.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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-cypress:
  9. type: boolean
  10. cypress-report-artifact-name-prefix:
  11. type: string
  12. cypress-config-video:
  13. type: boolean
  14. default: false
  15. secrets:
  16. SLACK_WEBHOOK_URL:
  17. required: true
  18. jobs:
  19. build-prod:
  20. runs-on: ubuntu-latest
  21. outputs:
  22. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  23. steps:
  24. - uses: actions/checkout@v4
  25. with:
  26. # retrieve local font files
  27. lfs: true
  28. - uses: actions/setup-node@v4
  29. with:
  30. node-version: ${{ inputs.node-version }}
  31. cache: 'yarn'
  32. cache-dependency-path: '**/yarn.lock'
  33. - name: Install turbo
  34. run: |
  35. yarn global add turbo
  36. - name: Prune repositories
  37. run: |
  38. turbo prune --scope=@growi/app
  39. rm -rf apps packages
  40. mv out/* .
  41. - name: Cache/Restore node_modules
  42. id: cache-dependencies
  43. uses: actions/cache@v4
  44. with:
  45. path: |
  46. **/node_modules
  47. key: node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  48. restore-keys: |
  49. node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  50. - name: Install dependencies
  51. run: |
  52. yarn global add node-gyp
  53. yarn --frozen-lockfile
  54. - name: Restore dist
  55. uses: actions/cache@v4
  56. with:
  57. path: |
  58. node_modules/.cache/turbo
  59. **/.turbo
  60. **/dist
  61. ${{ github.workspace }}/apps/app/.next
  62. key: dist-app-7.x-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.ref_name }}-${{ github.sha }}
  63. restore-keys: |
  64. dist-app-7.x-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.ref_name }}-
  65. dist-app-7.x-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  66. - name: Build
  67. working-directory: ./apps/app
  68. run: |
  69. turbo run build
  70. env:
  71. ANALYZE_BUNDLE_SIZE: 1
  72. - name: Archive production files
  73. id: archive-prod-files
  74. run: |
  75. tar -zcf production.tar.gz \
  76. package.json \
  77. apps/app/.next \
  78. apps/app/config \
  79. apps/app/dist \
  80. apps/app/public \
  81. apps/app/resource \
  82. apps/app/tmp \
  83. apps/app/.env.production* \
  84. apps/app/package.json \
  85. packages/*/dist \
  86. packages/*/package.json
  87. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  88. - name: Upload production files as artifact
  89. uses: actions/upload-artifact@v4
  90. with:
  91. name: Production Files (node${{ inputs.node-version }})
  92. path: ${{ steps.archive-prod-files.outputs.file }}
  93. - name: Upload report as artifact
  94. uses: actions/upload-artifact@v4
  95. with:
  96. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  97. path: |
  98. apps/app/.next/analyze/client.html
  99. apps/app/.next/analyze/server.html
  100. - name: Slack Notification
  101. uses: weseek/ghaction-slack-notification@master
  102. if: failure()
  103. with:
  104. type: ${{ job.status }}
  105. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  106. channel: '#ci'
  107. isCompactMode: true
  108. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  109. launch-prod:
  110. needs: [build-prod]
  111. runs-on: ubuntu-latest
  112. services:
  113. mongodb:
  114. image: mongo:6.0
  115. ports:
  116. - 27017/tcp
  117. elasticsearch:
  118. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  119. ports:
  120. - 9200/tcp
  121. env:
  122. discovery.type: single-node
  123. steps:
  124. - uses: actions/checkout@v4
  125. - uses: actions/setup-node@v4
  126. with:
  127. node-version: ${{ inputs.node-version }}
  128. cache: 'yarn'
  129. cache-dependency-path: '**/yarn.lock'
  130. - name: Install turbo
  131. run: |
  132. yarn global add turbo
  133. - name: Prune repositories
  134. run: |
  135. turbo prune --scope=@growi/app
  136. rm -rf apps packages
  137. mv out/* .
  138. - name: Cache/Restore node_modules
  139. id: cache-dependencies
  140. uses: actions/cache@v4
  141. with:
  142. path: |
  143. **/node_modules
  144. key: node_modules-app-7.x-launch-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  145. restore-keys: |
  146. node_modules-app-7.x-launch-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  147. - name: Install dependencies
  148. run: |
  149. yarn --production
  150. - name: Download production files artifact
  151. uses: actions/download-artifact@v4
  152. with:
  153. name: Production Files (node${{ inputs.node-version }})
  154. - name: Extract procution files artifact
  155. run: |
  156. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  157. - name: yarn server:ci
  158. working-directory: ./apps/app
  159. run: |
  160. cp config/ci/.env.local.for-ci .env.production.local
  161. yarn server:ci
  162. env:
  163. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  164. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  165. - name: Slack Notification
  166. uses: weseek/ghaction-slack-notification@master
  167. if: failure()
  168. with:
  169. type: ${{ job.status }}
  170. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  171. channel: '#ci'
  172. isCompactMode: true
  173. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  174. run-cypress:
  175. needs: [build-prod]
  176. if: ${{ !inputs.skip-cypress }}
  177. runs-on: ubuntu-latest
  178. strategy:
  179. fail-fast: false
  180. matrix:
  181. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  182. spec-group: ['10', '20', '21', '22', '23', '30', '40', '50', '60']
  183. services:
  184. mongodb:
  185. image: mongo:6.0
  186. ports:
  187. - 27017/tcp
  188. elasticsearch:
  189. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  190. ports:
  191. - 9200/tcp
  192. env:
  193. discovery.type: single-node
  194. steps:
  195. - uses: actions/checkout@v4
  196. - name: Install fonts
  197. run: sudo apt install fonts-noto
  198. - uses: actions/setup-node@v4
  199. with:
  200. node-version: ${{ inputs.node-version }}
  201. cache: 'yarn'
  202. cache-dependency-path: '**/yarn.lock'
  203. - name: Install turbo
  204. run: |
  205. yarn global add turbo
  206. - name: Prune repositories
  207. run: |
  208. turbo prune --scope=@growi/app
  209. rm -rf apps packages
  210. mv out/* .
  211. - name: Cache/Restore node_modules
  212. id: cache-dependencies
  213. uses: actions/cache@v4
  214. with:
  215. path: |
  216. **/node_modules
  217. key: node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  218. restore-keys: |
  219. node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  220. - name: Cache/Restore Cypress files
  221. uses: actions/cache@v4
  222. with:
  223. path: |
  224. ~/.cache/Cypress
  225. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  226. restore-keys: |
  227. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-
  228. - name: Install dependencies
  229. run: |
  230. yarn global add node-gyp
  231. yarn --frozen-lockfile
  232. yarn cypress install
  233. - name: Download production files artifact
  234. uses: actions/download-artifact@v4
  235. with:
  236. name: Production Files (node${{ inputs.node-version }})
  237. - name: Extract procution files artifact
  238. run: |
  239. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  240. - name: Determine spec expression
  241. id: determine-spec-exp
  242. run: |
  243. SPEC=`node bin/github-actions/generate-cypress-spec-arg.mjs --prefix="test/cypress/e2e/" --suffix="-*/*.cy.{ts,tsx}" "${{ matrix.spec-group }}"`
  244. echo "value=$SPEC" >> $GITHUB_OUTPUT
  245. - name: Copy dotenv file for ci
  246. working-directory: ./apps/app
  247. run: |
  248. cat config/ci/.env.local.for-ci >> .env.production.local
  249. - name: Copy dotenv file for automatic installation
  250. if: ${{ matrix.spec-group != '10' }}
  251. working-directory: ./apps/app
  252. run: |
  253. cat config/ci/.env.local.for-auto-install >> .env.production.local
  254. - name: Copy dotenv file for automatic installation with allowing guest mode
  255. if: ${{ matrix.spec-group == '21' }}
  256. working-directory: ./apps/app
  257. run: |
  258. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  259. - name: Cypress Run
  260. uses: cypress-io/github-action@v6
  261. with:
  262. browser: chromium
  263. working-directory: ./apps/app
  264. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  265. install: false
  266. start: yarn server
  267. wait-on: 'http://localhost:3000'
  268. config: video=${{ inputs.cypress-config-video }}
  269. env:
  270. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  271. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  272. - name: Upload results
  273. if: always()
  274. uses: actions/upload-artifact@v4
  275. with:
  276. name: ${{ inputs.cypress-report-artifact-name-prefix }}${{ matrix.spec-group }}
  277. path: |
  278. apps/app/test/cypress/screenshots
  279. apps/app/test/cypress/videos
  280. - name: Slack Notification
  281. uses: weseek/ghaction-slack-notification@master
  282. if: failure()
  283. with:
  284. type: ${{ job.status }}
  285. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  286. channel: '#ci'
  287. isCompactMode: true
  288. url: ${{ secrets.SLACK_WEBHOOK_URL }}