reusable-app-prod.yml 9.6 KB

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