reusable-app-prod.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. elasticsearch:
  80. image: docker.elastic.co/elasticsearch/elasticsearch:6.8.23
  81. ports:
  82. - 9200/tcp
  83. env:
  84. discovery.type: single-node
  85. steps:
  86. - uses: actions/checkout@v2
  87. - uses: actions/setup-node@v2
  88. with:
  89. node-version: ${{ inputs.node-version }}
  90. cache: 'yarn'
  91. cache-dependency-path: '**/yarn.lock'
  92. - name: Get Date
  93. id: get-date
  94. run: |
  95. echo "::set-output name=dateYmdHM::$(/bin/date -u "+%Y%m%d%H%M")"
  96. echo "::set-output name=dateYm::$(/bin/date -u "+%Y%m")"
  97. - name: Cache/Restore node_modules (not reused)
  98. id: cache-dependencies
  99. uses: actions/cache@v2
  100. with:
  101. path: |
  102. **/node_modules
  103. key: node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYmdHM }}
  104. restore-keys: |
  105. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  106. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  107. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYm }}
  108. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  109. - name: Remove unnecessary packages
  110. run: |
  111. rm -rf packages/slackbot-proxy
  112. - name: lerna bootstrap --production
  113. run: |
  114. npx lerna bootstrap -- --production
  115. - name: Download production files artifact
  116. uses: actions/download-artifact@v2
  117. with:
  118. name: Production Files
  119. - name: Extract procution files artifact
  120. run: |
  121. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  122. - name: yarn server:ci
  123. working-directory: ./packages/app
  124. run: |
  125. cp config/ci/.env.local.for-ci .env.production.local
  126. yarn server:ci
  127. env:
  128. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  129. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  130. - name: Slack Notification
  131. uses: weseek/ghaction-slack-notification@master
  132. if: failure()
  133. with:
  134. type: ${{ job.status }}
  135. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  136. channel: '#ci'
  137. isCompactMode: true
  138. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  139. run-cypress:
  140. needs: [build-prod]
  141. if: ${{ !inputs.skip-cypress }}
  142. runs-on: ubuntu-latest
  143. container:
  144. image: cypress/base:16.13.0
  145. # solve permissions issue
  146. # see: https://github.com/cypress-io/github-action/issues/446#issuecomment-987015822
  147. options: --user 1001
  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', '3']
  153. services:
  154. mongodb:
  155. image: mongo:4.4
  156. ports:
  157. - 27017/tcp
  158. elasticsearch:
  159. image: docker.elastic.co/elasticsearch/elasticsearch:6.8.23
  160. ports:
  161. - 9200/tcp
  162. env:
  163. discovery.type: single-node
  164. steps:
  165. - uses: actions/checkout@v2
  166. - name: Get yarn cache dir
  167. id: yarn-cache-dir
  168. run: |
  169. echo "::set-output name=value::`yarn cache dir --silent`"
  170. - name: Cache/Restore dependencies
  171. uses: actions/cache@v2
  172. with:
  173. path: |
  174. **/node_modules
  175. ~/.cache/Cypress
  176. ${{ steps.yarn-cache-dir.outputs.value }}
  177. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  178. restore-keys: |
  179. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}
  180. - name: lerna bootstrap
  181. run: |
  182. npx lerna bootstrap -- --frozen-lockfile
  183. - name: Download production files artifact
  184. uses: actions/download-artifact@v2
  185. with:
  186. name: Production Files
  187. - name: Extract procution files artifact
  188. run: |
  189. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  190. - name: Determine spec expression
  191. id: determine-spec-exp
  192. run: |
  193. SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.spec-group }}"`
  194. echo "::set-output name=value::$SPEC"
  195. - name: Copy dotenv file for ci
  196. working-directory: ./packages/app
  197. run: |
  198. cat config/ci/.env.local.for-ci >> .env.production.local
  199. - name: Copy dotenv file for automatic installation
  200. if: ${{ matrix.spec-group != '1' }}
  201. working-directory: ./packages/app
  202. run: |
  203. cat config/ci/.env.local.for-auto-install >> .env.production.local
  204. - name: Cypress Run
  205. uses: cypress-io/github-action@v2
  206. with:
  207. working-directory: ./packages/app
  208. install: false
  209. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  210. start: yarn server
  211. wait-on: 'http://localhost:3000'
  212. env:
  213. MONGO_URI: mongodb://mongodb:27017/growi-vrt
  214. ELASTICSEARCH_URI: http://elasticsearch:9200/growi
  215. - name: Upload results
  216. if: always()
  217. uses: actions/upload-artifact@v2
  218. with:
  219. name: ${{ inputs.cypress-report-artifact-name }}
  220. path: |
  221. packages/app/test/cypress/screenshots
  222. packages/app/test/cypress/videos
  223. - name: Slack Notification
  224. uses: weseek/ghaction-slack-notification@master
  225. if: failure()
  226. with:
  227. type: ${{ job.status }}
  228. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  229. channel: '#ci'
  230. isCompactMode: true
  231. url: ${{ secrets.SLACK_WEBHOOK_URL }}