reusable-app-prod.yml 7.9 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. npx-command:
  9. type: string
  10. default: npx -y
  11. skip-cypress:
  12. type: boolean
  13. cypress-report-artifact-name:
  14. type: string
  15. secrets:
  16. SLACK_WEBHOOK_URL:
  17. required: true
  18. jobs:
  19. build-prod:
  20. runs-on: ubuntu-latest
  21. outputs:
  22. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  23. steps:
  24. - uses: actions/checkout@v2
  25. - uses: actions/setup-node@v2
  26. with:
  27. node-version: ${{ inputs.node-version }}
  28. cache: 'yarn'
  29. cache-dependency-path: '**/yarn.lock'
  30. - name: Cache/Restore node_modules
  31. id: cache-dependencies
  32. uses: actions/cache@v2
  33. with:
  34. path: |
  35. **/node_modules
  36. key: node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  37. restore-keys: |
  38. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  39. - name: lerna bootstrap
  40. run: |
  41. ${{ inputs.npx-command }} lerna bootstrap -- --frozen-lockfile
  42. - name: Remove unnecessary packages
  43. run: |
  44. rm -rf packages/slackbot-proxy
  45. - name: Build
  46. run: |
  47. yarn lerna run build
  48. env:
  49. ANALYZE_BUNDLE_SIZE: 1
  50. - name: Archive production files
  51. id: archive-prod-files
  52. run: |
  53. tar -cf production.tar packages/**/dist packages/app/public
  54. echo ::set-output name=file::production.tar
  55. - name: Upload production files as artifact
  56. uses: actions/upload-artifact@v2
  57. with:
  58. name: Production Files
  59. path: ${{ steps.archive-prod-files.outputs.file }}
  60. - name: Upload report as artifact
  61. uses: actions/upload-artifact@v2
  62. with:
  63. name: Bundle Analyzing Report
  64. path: packages/app/report/bundle-analyzer.html
  65. - name: Slack Notification
  66. uses: weseek/ghaction-slack-notification@master
  67. if: failure()
  68. with:
  69. type: ${{ job.status }}
  70. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  71. channel: '#ci'
  72. isCompactMode: true
  73. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  74. launch-prod:
  75. needs: [build-prod]
  76. runs-on: ubuntu-latest
  77. services:
  78. mongodb:
  79. image: mongo:4.4
  80. ports:
  81. - 27017/tcp
  82. mongodb36:
  83. image: mongo:3.6
  84. ports:
  85. - 27017/tcp
  86. steps:
  87. - uses: actions/checkout@v2
  88. - uses: actions/setup-node@v2
  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@v2
  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') }}
  107. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  108. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYm }}
  109. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  110. - name: Remove unnecessary packages
  111. run: |
  112. rm -rf packages/slackbot-proxy
  113. - name: lerna bootstrap --production
  114. run: |
  115. ${{ inputs.npx-command }} lerna bootstrap -- --production
  116. - name: Download production files artifact
  117. uses: actions/download-artifact@v2
  118. with:
  119. name: Production Files
  120. - name: Extract procution files artifact
  121. run: |
  122. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  123. - name: yarn server:ci
  124. working-directory: ./packages/app
  125. run: |
  126. cp config/ci/.env.local.for-ci .env.production.local
  127. yarn server:ci
  128. env:
  129. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  130. - name: yarn server:ci with MongoDB 3.6
  131. working-directory: ./packages/app
  132. run: |
  133. cp config/ci/.env.local.for-ci .env.production.local
  134. yarn server:ci
  135. env:
  136. MONGO_URI: mongodb://localhost:${{ job.services.mongodb36.ports['27017'] }}/growi
  137. - name: Slack Notification
  138. uses: weseek/ghaction-slack-notification@master
  139. if: failure()
  140. with:
  141. type: ${{ job.status }}
  142. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  143. channel: '#ci'
  144. isCompactMode: true
  145. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  146. run-cypress:
  147. needs: [build-prod]
  148. if: ${{ !inputs.skip-cypress }}
  149. runs-on: ubuntu-latest
  150. container: cypress/base:16.13.0
  151. strategy:
  152. fail-fast: false
  153. matrix:
  154. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  155. spec-group: ['1', '2']
  156. services:
  157. mongodb:
  158. image: mongo:4.4
  159. ports:
  160. - 27017/tcp
  161. steps:
  162. - uses: actions/checkout@v2
  163. - uses: actions/setup-node@v2
  164. with:
  165. node-version: ${{ inputs.node-version }}
  166. cache: 'yarn'
  167. cache-dependency-path: '**/yarn.lock'
  168. # workaround by https://github.com/cypress-io/github-action/issues/407
  169. - name: Setup yarn cache settings
  170. run: yarn config set cache-folder ~/.cache/yarn
  171. - name: Cache/Restore node_modules
  172. uses: actions/cache@v2
  173. with:
  174. path: |
  175. **/node_modules
  176. ~/.cache/Cypress
  177. key: node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  178. restore-keys: |
  179. node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}
  180. - name: lerna bootstrap
  181. run: |
  182. whoami
  183. ls -al .
  184. ls -al packages/app
  185. npx -y 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@v2
  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. - name: Upload results
  218. if: always()
  219. uses: actions/upload-artifact@v2
  220. with:
  221. name: ${{ inputs.cypress-report-artifact-name }}
  222. path: |
  223. packages/app/test/cypress/screenshots
  224. packages/app/test/cypress/videos
  225. - name: Slack Notification
  226. uses: weseek/ghaction-slack-notification@master
  227. if: failure()
  228. with:
  229. type: ${{ job.status }}
  230. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  231. channel: '#ci'
  232. isCompactMode: true
  233. url: ${{ secrets.SLACK_WEBHOOK_URL }}