reusable-app-prod.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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:
  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. spec-group: ['50']
  184. services:
  185. mongodb:
  186. image: mongo:6.0
  187. ports:
  188. - 27017/tcp
  189. elasticsearch:
  190. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  191. ports:
  192. - 9200/tcp
  193. env:
  194. discovery.type: single-node
  195. steps:
  196. - uses: actions/checkout@v4
  197. - name: Install fonts
  198. run: sudo apt install fonts-noto
  199. - uses: actions/setup-node@v4
  200. with:
  201. node-version: ${{ inputs.node-version }}
  202. cache: 'yarn'
  203. cache-dependency-path: '**/yarn.lock'
  204. - name: Install turbo
  205. run: |
  206. yarn global add turbo
  207. - name: Prune repositories
  208. run: |
  209. turbo prune --scope=@growi/app
  210. rm -rf apps packages
  211. mv out/* .
  212. - name: Cache/Restore node_modules
  213. id: cache-dependencies
  214. uses: actions/cache@v4
  215. with:
  216. path: |
  217. **/node_modules
  218. key: node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  219. restore-keys: |
  220. node_modules-app-7.x-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  221. - name: Cache/Restore Cypress files
  222. uses: actions/cache@v4
  223. with:
  224. path: |
  225. ~/.cache/Cypress
  226. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  227. restore-keys: |
  228. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-
  229. - name: Install dependencies
  230. run: |
  231. yarn global add node-gyp
  232. yarn --frozen-lockfile
  233. yarn cypress install
  234. - name: Download production files artifact
  235. uses: actions/download-artifact@v4
  236. with:
  237. name: Production Files (node${{ inputs.node-version }})
  238. - name: Extract procution files artifact
  239. run: |
  240. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  241. - name: Determine spec expression
  242. id: determine-spec-exp
  243. run: |
  244. SPEC=`node bin/github-actions/generate-cypress-spec-arg.mjs --prefix="test/cypress/e2e/" --suffix="-*/*.cy.{ts,tsx}" "${{ matrix.spec-group }}"`
  245. echo "value=$SPEC" >> $GITHUB_OUTPUT
  246. - name: Copy dotenv file for ci
  247. working-directory: ./apps/app
  248. run: |
  249. cat config/ci/.env.local.for-ci >> .env.production.local
  250. - name: Copy dotenv file for automatic installation
  251. if: ${{ matrix.spec-group != '10' }}
  252. working-directory: ./apps/app
  253. run: |
  254. cat config/ci/.env.local.for-auto-install >> .env.production.local
  255. - name: Copy dotenv file for automatic installation with allowing guest mode
  256. if: ${{ matrix.spec-group == '21' }}
  257. working-directory: ./apps/app
  258. run: |
  259. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  260. - name: Cypress Run
  261. uses: cypress-io/github-action@v6
  262. with:
  263. browser: chromium
  264. working-directory: ./apps/app
  265. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  266. install: false
  267. start: yarn server
  268. wait-on: 'http://localhost:3000'
  269. config: video=${{ inputs.cypress-config-video }}
  270. env:
  271. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  272. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  273. - name: Upload results
  274. if: always()
  275. uses: actions/upload-artifact@v4
  276. with:
  277. name: ${{ inputs.cypress-report-artifact-name }}
  278. path: |
  279. apps/app/test/cypress/screenshots
  280. apps/app/test/cypress/videos
  281. - name: Slack Notification
  282. uses: weseek/ghaction-slack-notification@master
  283. if: failure()
  284. with:
  285. type: ${{ job.status }}
  286. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  287. channel: '#ci'
  288. isCompactMode: true
  289. url: ${{ secrets.SLACK_WEBHOOK_URL }}