reusable-app-prod.yml 7.7 KB

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