reusable-app-prod.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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-e2e-test:
  9. type: boolean
  10. cypress-report-artifact-name-prefix:
  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@v4
  25. with:
  26. # retrieve local font files
  27. lfs: true
  28. - uses: actions/setup-node@v4
  29. with:
  30. node-version: ${{ inputs.node-version }}
  31. cache: 'yarn'
  32. cache-dependency-path: '**/yarn.lock'
  33. - name: Install turbo
  34. run: |
  35. yarn global add turbo
  36. - name: Prune repositories
  37. run: |
  38. turbo prune @growi/app
  39. rm -rf apps packages
  40. mv out/* .
  41. - name: Cache/Restore node_modules
  42. uses: actions/cache@v4
  43. with:
  44. path: |
  45. **/node_modules
  46. !**/node_modules/.cache/turbo
  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 global add node-gyp
  53. yarn --frozen-lockfile
  54. - name: Cache/Restore dist
  55. uses: actions/cache@v4
  56. with:
  57. path: |
  58. **/.turbo
  59. **/dist
  60. **/node_modules/.cache/turbo
  61. ${{ github.workspace }}/apps/app/.next
  62. key: dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ github.sha }}
  63. restore-keys: |
  64. dist-app-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  65. - name: Build
  66. working-directory: ./apps/app
  67. run: |
  68. turbo run build --env-mode=loose
  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@v4
  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@v4
  94. with:
  95. name: Bundle Analyzing Report (node${{ inputs.node-version }})
  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@v4
  124. - uses: actions/setup-node@v4
  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 @growi/app
  135. rm -rf apps packages
  136. mv out/* .
  137. - name: Restore node_modules
  138. uses: actions/cache/restore@v4
  139. with:
  140. path: |
  141. **/node_modules
  142. # shared key with build-prod
  143. key: node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  144. restore-keys: |
  145. node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  146. - name: Install dependencies
  147. run: |
  148. yarn --production
  149. - name: Cache node_modules for production
  150. uses: actions/cache/save@v4
  151. with:
  152. path: |
  153. **/node_modules
  154. key: node_modules-app-launch-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  155. - name: Download production files artifact
  156. uses: actions/download-artifact@v4
  157. with:
  158. name: Production Files (node${{ inputs.node-version }})
  159. - name: Extract procution files artifact
  160. run: |
  161. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  162. - name: yarn server:ci
  163. working-directory: ./apps/app
  164. run: |
  165. cp config/ci/.env.local.for-ci .env.production.local
  166. yarn server:ci
  167. env:
  168. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  169. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  170. - name: Slack Notification
  171. uses: weseek/ghaction-slack-notification@master
  172. if: failure()
  173. with:
  174. type: ${{ job.status }}
  175. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  176. channel: '#ci'
  177. isCompactMode: true
  178. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  179. run-cypress:
  180. needs: [build-prod]
  181. if: ${{ !inputs.skip-e2e-test }}
  182. runs-on: ubuntu-latest
  183. strategy:
  184. fail-fast: false
  185. matrix:
  186. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  187. spec-group: ['20', '21', '22', '23', '30', '40', '50', '60']
  188. services:
  189. mongodb:
  190. image: mongo:6.0
  191. ports:
  192. - 27017/tcp
  193. elasticsearch:
  194. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  195. ports:
  196. - 9200/tcp
  197. env:
  198. discovery.type: single-node
  199. steps:
  200. - uses: actions/checkout@v4
  201. - name: Install fonts
  202. run: sudo apt install fonts-noto
  203. - uses: actions/setup-node@v4
  204. with:
  205. node-version: ${{ inputs.node-version }}
  206. cache: 'yarn'
  207. cache-dependency-path: '**/yarn.lock'
  208. - name: Install turbo
  209. run: |
  210. yarn global add turbo
  211. - name: Prune repositories
  212. run: |
  213. turbo prune @growi/app
  214. rm -rf apps packages
  215. mv out/* .
  216. - name: Restore node_modules
  217. uses: actions/cache/restore@v4
  218. with:
  219. path: |
  220. **/node_modules
  221. # saved key by launch-prod
  222. key: node_modules-app-launch-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  223. restore-keys: |
  224. node_modules-app-launch-prod-${{ runner.OS }}--node${{ inputs.node-version }}-
  225. - name: Cache/Restore Cypress files
  226. uses: actions/cache@v4
  227. with:
  228. path: |
  229. ~/.cache/Cypress
  230. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  231. restore-keys: |
  232. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-
  233. - name: Install dependencies
  234. run: |
  235. yarn global add node-gyp
  236. yarn --production
  237. yarn cypress install
  238. - name: Download production files artifact
  239. uses: actions/download-artifact@v4
  240. with:
  241. name: Production Files (node${{ inputs.node-version }})
  242. - name: Extract procution files artifact
  243. run: |
  244. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  245. - name: Determine spec expression
  246. id: determine-spec-exp
  247. run: |
  248. SPEC=`node bin/github-actions/generate-cypress-spec-arg.mjs --prefix="test/cypress/e2e/" --suffix="-*/*.cy.{ts,tsx}" "${{ matrix.spec-group }}"`
  249. echo "value=$SPEC" >> $GITHUB_OUTPUT
  250. - name: Copy dotenv file for ci
  251. working-directory: ./apps/app
  252. run: |
  253. cat config/ci/.env.local.for-ci >> .env.production.local
  254. - name: Copy dotenv file for automatic installation
  255. if: ${{ matrix.spec-group != '10' }}
  256. working-directory: ./apps/app
  257. run: |
  258. cat config/ci/.env.local.for-auto-install >> .env.production.local
  259. - name: Copy dotenv file for automatic installation with allowing guest mode
  260. if: ${{ matrix.spec-group == '21' }}
  261. working-directory: ./apps/app
  262. run: |
  263. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  264. - name: Cypress Run
  265. uses: cypress-io/github-action@v6
  266. with:
  267. browser: chromium
  268. working-directory: ./apps/app
  269. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  270. install: false
  271. start: yarn server
  272. wait-on: 'http://localhost:3000'
  273. config: video=${{ inputs.cypress-config-video }}
  274. env:
  275. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  276. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  277. - name: Upload results
  278. if: always()
  279. uses: actions/upload-artifact@v4
  280. with:
  281. name: ${{ inputs.cypress-report-artifact-name-prefix }}${{ matrix.spec-group }}
  282. path: |
  283. apps/app/test/cypress/screenshots
  284. apps/app/test/cypress/videos
  285. - name: Slack Notification
  286. uses: weseek/ghaction-slack-notification@master
  287. if: failure()
  288. with:
  289. type: ${{ job.status }}
  290. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  291. channel: '#ci'
  292. isCompactMode: true
  293. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  294. run-playwright:
  295. needs: [build-prod]
  296. if: ${{ !inputs.skip-e2e-test }}
  297. runs-on: ubuntu-latest
  298. container:
  299. image: mcr.microsoft.com/playwright:latest
  300. strategy:
  301. fail-fast: false
  302. matrix:
  303. browser: [chromium, firefox, webkit]
  304. shard: [1/2, 2/2]
  305. services:
  306. mongodb:
  307. image: mongo:6.0
  308. ports:
  309. - 27017/tcp
  310. elasticsearch:
  311. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  312. ports:
  313. - 9200/tcp
  314. env:
  315. discovery.type: single-node
  316. steps:
  317. - uses: actions/checkout@v4
  318. - uses: actions/setup-node@v4
  319. with:
  320. node-version: ${{ inputs.node-version }}
  321. cache: 'yarn'
  322. cache-dependency-path: '**/yarn.lock'
  323. - name: Restore node_modules
  324. uses: actions/cache/restore@v4
  325. with:
  326. path: |
  327. **/node_modules
  328. # saved key by launch-prod
  329. key: node_modules-app-launch-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  330. restore-keys: |
  331. node_modules-app-launch-prod-${{ runner.OS }}--node${{ inputs.node-version }}-
  332. - name: Install dependencies
  333. run: |
  334. yarn global add node-gyp
  335. yarn --production
  336. - name: Install Playwright browsers
  337. run: |
  338. yarn playwright install --with-deps ${{ matrix.browser }}
  339. - name: Download production files artifact
  340. uses: actions/download-artifact@v4
  341. with:
  342. name: Production Files (node${{ inputs.node-version }})
  343. - name: Extract procution files artifact
  344. run: |
  345. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  346. - name: Copy dotenv file for ci
  347. working-directory: ./apps/app
  348. run: |
  349. cat config/ci/.env.local.for-ci >> .env.production.local
  350. - name: Playwright Run (--project=chromium/installer)
  351. if: ${{ matrix.browser == 'chromium' }}
  352. working-directory: ./apps/app
  353. run: |
  354. yarn playwright test --project=chromium/installer
  355. env:
  356. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  357. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  358. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  359. - name: Copy dotenv file for automatic installation
  360. working-directory: ./apps/app
  361. run: |
  362. cat config/ci/.env.local.for-auto-install >> .env.production.local
  363. # - name: Copy dotenv file for automatic installation with allowing guest mode
  364. # if: ${{ matrix.spec-group == '21' }}
  365. # working-directory: ./apps/app
  366. # run: |
  367. # cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  368. - name: Playwright Run
  369. working-directory: ./apps/app
  370. run: |
  371. yarn playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  372. env:
  373. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  374. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  375. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  376. - name: Slack Notification
  377. uses: weseek/ghaction-slack-notification@master
  378. if: failure()
  379. with:
  380. type: ${{ job.status }}
  381. job_name: '*Node CI for growi - run-playwright*'
  382. channel: '#ci'
  383. isCompactMode: true
  384. url: ${{ secrets.SLACK_WEBHOOK_URL }}