reusable-app-prod.yml 9.5 KB

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