reusable-app-prod.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. required: true
  12. type: string
  13. secrets:
  14. SLACK_WEBHOOK_URL:
  15. required: true
  16. jobs:
  17. build-prod:
  18. runs-on: ubuntu-latest
  19. outputs:
  20. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  21. steps:
  22. - uses: actions/checkout@v2
  23. - uses: actions/setup-node@v2
  24. with:
  25. node-version: ${{ inputs.node-version }}
  26. cache: 'yarn'
  27. cache-dependency-path: '**/yarn.lock'
  28. - name: Cache/Restore node_modules
  29. id: cache-dependencies
  30. uses: actions/cache@v2
  31. with:
  32. path: |
  33. **/node_modules
  34. key: node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  35. restore-keys: |
  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. mongodb36:
  81. image: mongo:3.6
  82. ports:
  83. - 27017/tcp
  84. steps:
  85. - uses: actions/checkout@v2
  86. - uses: actions/setup-node@v2
  87. with:
  88. node-version: ${{ inputs.node-version }}
  89. cache: 'yarn'
  90. cache-dependency-path: '**/yarn.lock'
  91. - name: Get Date
  92. id: get-date
  93. run: |
  94. echo "::set-output name=dateYmdHM::$(/bin/date -u "+%Y%m%d%H%M")"
  95. echo "::set-output name=dateYm::$(/bin/date -u "+%Y%m")"
  96. - name: Cache/Restore node_modules (not reused)
  97. id: cache-dependencies
  98. uses: actions/cache@v2
  99. with:
  100. path: |
  101. **/node_modules
  102. key: node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYmdHM }}
  103. restore-keys: |
  104. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  105. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  106. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYm }}
  107. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  108. - name: Remove unnecessary packages
  109. run: |
  110. rm -rf packages/slackbot-proxy
  111. - name: lerna bootstrap --production
  112. run: |
  113. npx lerna bootstrap -- --production
  114. - name: Download production files artifact
  115. uses: actions/download-artifact@v2
  116. with:
  117. name: Production Files
  118. - name: Extract procution files artifact
  119. run: |
  120. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  121. - name: yarn server:ci
  122. working-directory: ./packages/app
  123. run: |
  124. cp config/ci/.env.local.for-ci .env.production.local
  125. yarn server:ci
  126. env:
  127. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  128. - name: yarn server:ci with MongoDB 3.6
  129. working-directory: ./packages/app
  130. run: |
  131. cp config/ci/.env.local.for-ci .env.production.local
  132. yarn server:ci
  133. env:
  134. MONGO_URI: mongodb://localhost:${{ job.services.mongodb36.ports['27017'] }}/growi
  135. - name: Slack Notification
  136. uses: weseek/ghaction-slack-notification@master
  137. if: failure()
  138. with:
  139. type: ${{ job.status }}
  140. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  141. channel: '#ci'
  142. isCompactMode: true
  143. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  144. run-cypress:
  145. needs: [build-prod]
  146. if: ${{ !inputs.skip-cypress }}
  147. runs-on: ubuntu-latest
  148. container: cypress/base:14.18.1
  149. strategy:
  150. fail-fast: false
  151. matrix:
  152. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  153. spec-group: ['1', '2']
  154. services:
  155. mongodb:
  156. image: mongo:4.4
  157. ports:
  158. - 27017/tcp
  159. steps:
  160. - uses: actions/checkout@v2
  161. - uses: actions/setup-node@v2
  162. with:
  163. node-version: ${{ inputs.node-version }}
  164. cache: 'yarn'
  165. cache-dependency-path: '**/yarn.lock'
  166. # workaround by https://github.com/cypress-io/github-action/issues/407
  167. - name: Setup yarn cache settings
  168. run: yarn config set cache-folder ~/.cache/yarn
  169. - name: Cache/Restore node_modules
  170. uses: actions/cache@v2
  171. with:
  172. path: |
  173. **/node_modules
  174. ~/.cache/Cypress
  175. key: node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  176. restore-keys: |
  177. node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}
  178. - name: lerna bootstrap
  179. run: |
  180. npx lerna bootstrap -- --frozen-lockfile
  181. - name: Download production files artifact
  182. uses: actions/download-artifact@v2
  183. with:
  184. name: Production Files
  185. - name: Extract procution files artifact
  186. run: |
  187. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  188. - name: Determine spec expression
  189. id: determine-spec-exp
  190. run: |
  191. SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.spec-group }}"`
  192. echo "::set-output name=value::$SPEC"
  193. - name: Cypress Run
  194. uses: cypress-io/github-action@v2
  195. with:
  196. working-directory: ./packages/app
  197. install: false
  198. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  199. build: |
  200. cp config/ci/.env.local.for-ci .env.production.local
  201. start: yarn server
  202. wait-on: 'http://localhost:3000'
  203. env:
  204. MONGO_URI: mongodb://mongodb:27017/growi-vrt
  205. - name: Upload results
  206. if: always()
  207. uses: actions/upload-artifact@v2
  208. with:
  209. name: ${{ inputs.cypress-report-artifact-name }}
  210. path: |
  211. packages/app/test/cypress/screenshots
  212. packages/app/test/cypress/videos
  213. - name: Slack Notification
  214. uses: weseek/ghaction-slack-notification@master
  215. if: failure()
  216. with:
  217. type: ${{ job.status }}
  218. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  219. channel: '#ci'
  220. isCompactMode: true
  221. url: ${{ secrets.SLACK_WEBHOOK_URL }}