reusable-app-prod.yml 9.2 KB

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