reusable-app-prod.yml 9.5 KB

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