reusable-app-prod.yml 8.7 KB

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