reusable-app-prod.yml 14 KB

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