reusable-app-prod.yml 9.7 KB

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