reusable-app-prod.yml 9.2 KB

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