reusable-app-prod.yml 9.3 KB

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