reusable-app-prod.yml 7.7 KB

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