reusable-app-prod.yml 9.3 KB

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