reusable-app-prod.yml 9.6 KB

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