reusable-app-prod.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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: 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: Download production files artifact
  150. uses: actions/download-artifact@v4
  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-e2e-test }}
  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: ['21', '23', '30', '50']
  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@v4
  195. - name: Install fonts
  196. run: sudo apt install fonts-noto
  197. - uses: actions/setup-node@v4
  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: Prune repositories
  206. run: |
  207. turbo prune @growi/app
  208. rm -rf apps packages
  209. mv out/* .
  210. - name: Restore node_modules
  211. uses: actions/cache/restore@v4
  212. with:
  213. path: |
  214. **/node_modules
  215. # saved key by build-prod
  216. key: node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  217. restore-keys: |
  218. node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  219. - name: Cache/Restore Cypress files
  220. uses: actions/cache@v4
  221. with:
  222. path: |
  223. ~/.cache/Cypress
  224. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  225. restore-keys: |
  226. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-
  227. - name: Install dependencies
  228. run: |
  229. yarn global add node-gyp
  230. yarn --frozen-lockfile
  231. yarn cypress install
  232. - name: Download production files artifact
  233. uses: actions/download-artifact@v4
  234. with:
  235. name: Production Files (node${{ inputs.node-version }})
  236. - name: Extract procution files artifact
  237. run: |
  238. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  239. - name: Determine spec expression
  240. id: determine-spec-exp
  241. run: |
  242. SPEC=`node bin/github-actions/generate-cypress-spec-arg.mjs --prefix="test/cypress/e2e/" --suffix="-*/*.cy.{ts,tsx}" "${{ matrix.spec-group }}"`
  243. echo "value=$SPEC" >> $GITHUB_OUTPUT
  244. - name: Copy dotenv file for ci
  245. working-directory: ./apps/app
  246. run: |
  247. cat config/ci/.env.local.for-ci >> .env.production.local
  248. - name: Copy dotenv file for automatic installation
  249. if: ${{ matrix.spec-group != '10' }}
  250. working-directory: ./apps/app
  251. run: |
  252. cat config/ci/.env.local.for-auto-install >> .env.production.local
  253. - name: Copy dotenv file for automatic installation with allowing guest mode
  254. if: ${{ matrix.spec-group == '21' }}
  255. working-directory: ./apps/app
  256. run: |
  257. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  258. - name: Cypress Run
  259. uses: cypress-io/github-action@v6
  260. with:
  261. browser: chromium
  262. working-directory: ./apps/app
  263. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  264. install: false
  265. start: yarn server
  266. wait-on: 'http://localhost:3000'
  267. config: video=${{ inputs.cypress-config-video }}
  268. env:
  269. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  270. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  271. - name: Upload results
  272. if: always()
  273. uses: actions/upload-artifact@v4
  274. with:
  275. name: ${{ inputs.cypress-report-artifact-name-prefix }}${{ matrix.spec-group }}
  276. path: |
  277. apps/app/test/cypress/screenshots
  278. apps/app/test/cypress/videos
  279. - name: Slack Notification
  280. uses: weseek/ghaction-slack-notification@master
  281. if: failure()
  282. with:
  283. type: ${{ job.status }}
  284. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  285. channel: '#ci'
  286. isCompactMode: true
  287. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  288. run-playwright:
  289. needs: [build-prod]
  290. if: ${{ !inputs.skip-e2e-test }}
  291. runs-on: ubuntu-latest
  292. container:
  293. image: mcr.microsoft.com/playwright:latest
  294. strategy:
  295. fail-fast: false
  296. matrix:
  297. browser: [chromium, firefox, webkit]
  298. shard: [1/2, 2/2]
  299. services:
  300. mongodb:
  301. image: mongo:6.0
  302. ports:
  303. - 27017/tcp
  304. elasticsearch:
  305. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  306. ports:
  307. - 9200/tcp
  308. env:
  309. discovery.type: single-node
  310. steps:
  311. - uses: actions/checkout@v4
  312. - uses: actions/setup-node@v4
  313. with:
  314. node-version: ${{ inputs.node-version }}
  315. cache: 'yarn'
  316. cache-dependency-path: '**/yarn.lock'
  317. - name: Restore node_modules
  318. uses: actions/cache/restore@v4
  319. with:
  320. path: |
  321. **/node_modules
  322. # saved key by build-prod
  323. key: node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  324. restore-keys: |
  325. node_modules-app-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  326. - name: Install dependencies
  327. run: |
  328. yarn global add node-gyp
  329. yarn --frozen-lockfile
  330. - name: Install Playwright browsers
  331. run: |
  332. yarn playwright install --with-deps ${{ matrix.browser }}
  333. - name: Download production files artifact
  334. uses: actions/download-artifact@v4
  335. with:
  336. name: Production Files (node${{ inputs.node-version }})
  337. - name: Extract procution files artifact
  338. run: |
  339. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  340. - name: Copy dotenv file for ci
  341. working-directory: ./apps/app
  342. run: |
  343. cat config/ci/.env.local.for-ci >> .env.production.local
  344. - name: Playwright Run (--project=chromium/installer)
  345. if: ${{ matrix.browser == 'chromium' }}
  346. working-directory: ./apps/app
  347. run: |
  348. yarn playwright test --project=chromium/installer
  349. env:
  350. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  351. MONGO_URI: mongodb://mongodb:27017/growi-playwright-installer
  352. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  353. - name: Copy dotenv file for automatic installation
  354. working-directory: ./apps/app
  355. run: |
  356. cat config/ci/.env.local.for-auto-install >> .env.production.local
  357. - name: Playwright Run
  358. working-directory: ./apps/app
  359. run: |
  360. yarn playwright test --project=${{ matrix.browser }} --shard=${{ matrix.shard }}
  361. env:
  362. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  363. MONGO_URI: mongodb://mongodb:27017/growi-playwright
  364. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  365. - name: Copy dotenv file for automatic installation with allowing guest mode
  366. working-directory: ./apps/app
  367. run: |
  368. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  369. - name: Playwright Run (--project=${browser}/guest-mode)
  370. working-directory: ./apps/app
  371. run: |
  372. yarn playwright test --project=${{ matrix.browser }}/guest-mode --shard=${{ matrix.shard }}
  373. env:
  374. HOME: /root # ref: https://github.com/microsoft/playwright/issues/6500
  375. MONGO_URI: mongodb://mongodb:27017/growi-playwright-guest-mode
  376. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  377. - name: Slack Notification
  378. uses: weseek/ghaction-slack-notification@master
  379. if: failure()
  380. with:
  381. type: ${{ job.status }}
  382. job_name: '*Node CI for growi - run-playwright*'
  383. channel: '#ci'
  384. isCompactMode: true
  385. url: ${{ secrets.SLACK_WEBHOOK_URL }}