reusable-app-prod.yml 8.3 KB

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