reusable-app-prod.yml 8.8 KB

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