reusable-app-prod.yml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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: Cache/Restore node_modules
  31. id: cache-dependencies
  32. uses: actions/cache@v3
  33. with:
  34. path: |
  35. **/node_modules
  36. key: node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/app/package.json') }}
  37. restore-keys: |
  38. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-
  39. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  40. - name: lerna bootstrap
  41. run: |
  42. npx lerna bootstrap -- --frozen-lockfile
  43. - name: Remove unnecessary packages
  44. run: |
  45. rm -rf packages/slackbot-proxy
  46. rm -f "node_modules/@growi/slackbot-proxy"
  47. - name: Build
  48. run: |
  49. yarn lerna run build
  50. env:
  51. ANALYZE_BUNDLE_SIZE: 1
  52. - name: Archive production files
  53. id: archive-prod-files
  54. run: |
  55. tar -zcf production.tar.gz \
  56. package.json \
  57. packages/app/.next \
  58. packages/app/config \
  59. packages/app/public \
  60. packages/app/resource \
  61. packages/app/tmp \
  62. packages/app/.env.production* \
  63. packages/*/package.json \
  64. packages/*/dist
  65. echo "file=production.tar.gz" >> $GITHUB_OUTPUT
  66. - name: Upload production files as artifact
  67. uses: actions/upload-artifact@v3
  68. with:
  69. name: Production Files (node${{ inputs.node-version }})
  70. path: ${{ steps.archive-prod-files.outputs.file }}
  71. - name: Upload report as artifact
  72. uses: actions/upload-artifact@v3
  73. with:
  74. name: Bundle Analyzing Report
  75. path: |
  76. packages/app/.next/analyze/client.html
  77. packages/app/.next/analyze/server.html
  78. - name: Slack Notification
  79. uses: weseek/ghaction-slack-notification@master
  80. if: failure()
  81. with:
  82. type: ${{ job.status }}
  83. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  84. channel: '#ci'
  85. isCompactMode: true
  86. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  87. launch-prod:
  88. needs: [build-prod]
  89. runs-on: ubuntu-latest
  90. services:
  91. mongodb:
  92. image: mongo:4.4
  93. ports:
  94. - 27017/tcp
  95. elasticsearch:
  96. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  97. ports:
  98. - 9200/tcp
  99. env:
  100. discovery.type: single-node
  101. steps:
  102. - uses: actions/checkout@v3
  103. - uses: actions/setup-node@v3
  104. with:
  105. node-version: ${{ inputs.node-version }}
  106. cache: 'yarn'
  107. cache-dependency-path: '**/yarn.lock'
  108. - name: Get Date
  109. id: get-date
  110. run: |
  111. echo "dateYmdHM=$(/bin/date -u "+%Y%m%d%H%M")" >> $GITHUB_OUTPUT
  112. echo "dateYm=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
  113. - name: Cache/Restore node_modules (not reused)
  114. id: cache-dependencies
  115. uses: actions/cache@v3
  116. with:
  117. path: |
  118. **/node_modules
  119. key: node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYmdHM }}
  120. restore-keys: |
  121. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/app/package.json') }}
  122. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  123. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  124. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYm }}
  125. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  126. - name: Remove unnecessary packages
  127. run: |
  128. rm -rf packages/slackbot-proxy
  129. rm -f "node_modules/@growi/slackbot-proxy"
  130. - name: lerna bootstrap --production
  131. run: |
  132. npx lerna bootstrap -- --production
  133. - name: Download production files artifact
  134. uses: actions/download-artifact@v3
  135. with:
  136. name: Production Files (node${{ inputs.node-version }})
  137. - name: Extract procution files artifact
  138. run: |
  139. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  140. - name: yarn server:ci
  141. working-directory: ./packages/app
  142. run: |
  143. cp config/ci/.env.local.for-ci .env.production.local
  144. yarn server:ci
  145. env:
  146. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  147. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  148. - name: Slack Notification
  149. uses: weseek/ghaction-slack-notification@master
  150. if: failure()
  151. with:
  152. type: ${{ job.status }}
  153. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  154. channel: '#ci'
  155. isCompactMode: true
  156. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  157. run-cypress:
  158. needs: [build-prod]
  159. if: ${{ !inputs.skip-cypress }}
  160. runs-on: ubuntu-latest
  161. strategy:
  162. fail-fast: false
  163. matrix:
  164. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  165. spec-group: ['10', '20', '21', '22', '30', '40', '50', '60']
  166. services:
  167. mongodb:
  168. image: mongo:4.4
  169. ports:
  170. - 27017/tcp
  171. elasticsearch:
  172. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
  173. ports:
  174. - 9200/tcp
  175. env:
  176. discovery.type: single-node
  177. steps:
  178. - uses: actions/checkout@v3
  179. - name: Install fonts
  180. run: sudo apt install fonts-noto
  181. - uses: actions/setup-node@v3
  182. with:
  183. node-version: ${{ inputs.node-version }}
  184. cache: 'yarn'
  185. cache-dependency-path: '**/yarn.lock'
  186. - name: Cache/Restore dependencies
  187. uses: actions/cache@v3
  188. with:
  189. path: |
  190. **/node_modules
  191. ~/.cache/Cypress
  192. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/app/package.json') }}
  193. restore-keys: |
  194. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-
  195. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}
  196. - name: lerna bootstrap
  197. run: |
  198. npx lerna bootstrap -- --production
  199. - name: lerna add packages needed for CI
  200. run: |
  201. npx lerna add yargs
  202. - name: Download production files artifact
  203. uses: actions/download-artifact@v3
  204. with:
  205. name: Production Files (node${{ inputs.node-version }})
  206. - name: Extract procution files artifact
  207. run: |
  208. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  209. - name: Determine spec expression
  210. id: determine-spec-exp
  211. run: |
  212. SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.spec-group }}"`
  213. echo "value=$SPEC" >> $GITHUB_OUTPUT
  214. - name: Copy dotenv file for ci
  215. working-directory: ./packages/app
  216. run: |
  217. cat config/ci/.env.local.for-ci >> .env.production.local
  218. - name: Copy dotenv file for automatic installation
  219. if: ${{ matrix.spec-group != '10' }}
  220. working-directory: ./packages/app
  221. run: |
  222. cat config/ci/.env.local.for-auto-install >> .env.production.local
  223. - name: Copy dotenv file for automatic installation with allowing guest mode
  224. if: ${{ matrix.spec-group == '21' }}
  225. working-directory: ./packages/app
  226. run: |
  227. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  228. - name: Cypress Run
  229. uses: cypress-io/github-action@v3
  230. with:
  231. browser: chrome
  232. working-directory: ./packages/app
  233. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  234. start: yarn server
  235. wait-on: 'http://localhost:3000'
  236. config: video=${{ inputs.cypress-config-video }}
  237. env:
  238. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  239. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  240. - name: Upload results
  241. if: always()
  242. uses: actions/upload-artifact@v3
  243. with:
  244. name: ${{ inputs.cypress-report-artifact-name }}
  245. path: |
  246. packages/app/test/cypress/screenshots
  247. packages/app/test/cypress/videos
  248. - name: Slack Notification
  249. uses: weseek/ghaction-slack-notification@master
  250. if: failure()
  251. with:
  252. type: ${{ job.status }}
  253. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  254. channel: '#ci'
  255. isCompactMode: true
  256. url: ${{ secrets.SLACK_WEBHOOK_URL }}