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:
  148. image: cypress/base:16.13.0
  149. # solve permissions issue
  150. # see: https://github.com/cypress-io/github-action/issues/446#issuecomment-987015822
  151. options: --user 1001
  152. strategy:
  153. fail-fast: false
  154. matrix:
  155. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  156. spec-group: ['1', '2', '3']
  157. services:
  158. mongodb:
  159. image: mongo:4.4
  160. ports:
  161. - 27017/tcp
  162. steps:
  163. - uses: actions/checkout@v2
  164. - name: Get yarn cache dir
  165. id: yarn-cache-dir
  166. run: |
  167. echo "::set-output name=value::`yarn cache dir --silent`"
  168. - name: Cache/Restore dependencies
  169. uses: actions/cache@v2
  170. with:
  171. path: |
  172. **/node_modules
  173. ~/.cache/Cypress
  174. ${{ steps.yarn-cache-dir.outputs.value }}
  175. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  176. restore-keys: |
  177. deps-for-cypress-${{ 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: Copy dotenv file for ci
  194. working-directory: ./packages/app
  195. run: |
  196. cat config/ci/.env.local.for-ci >> .env.production.local
  197. - name: Copy dotenv file for automatic installation
  198. if: ${{ matrix.spec-group != '1' }}
  199. working-directory: ./packages/app
  200. run: |
  201. cat config/ci/.env.local.for-auto-install >> .env.production.local
  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. start: yarn server
  209. wait-on: 'http://localhost:3000'
  210. env:
  211. MONGO_URI: mongodb://mongodb:27017/growi-vrt
  212. - name: Upload results
  213. if: always()
  214. uses: actions/upload-artifact@v2
  215. with:
  216. name: ${{ inputs.cypress-report-artifact-name }}
  217. path: |
  218. packages/app/test/cypress/screenshots
  219. packages/app/test/cypress/videos
  220. - name: Slack Notification
  221. uses: weseek/ghaction-slack-notification@master
  222. if: failure()
  223. with:
  224. type: ${{ job.status }}
  225. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  226. channel: '#ci'
  227. isCompactMode: true
  228. url: ${{ secrets.SLACK_WEBHOOK_URL }}