reusable-app-prod.yml 9.0 KB

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