reusable-app-prod.yml 9.6 KB

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