2
0

reusable-app-prod.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. - name: Install fonts
  173. run: sudo apt install fonts-noto
  174. - uses: actions/setup-node@v3
  175. with:
  176. node-version: ${{ matrix.node-version }}
  177. cache: 'yarn'
  178. cache-dependency-path: '**/yarn.lock'
  179. - name: Cache/Restore dependencies
  180. uses: actions/cache@v3
  181. with:
  182. path: |
  183. **/node_modules
  184. ~/.cache/Cypress
  185. key: deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/app/package.json') }}
  186. restore-keys: |
  187. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}-
  188. deps-for-cypress-${{ runner.OS }}-node${{ inputs.node-version }}
  189. - name: lerna bootstrap
  190. run: |
  191. npx lerna bootstrap -- --frozen-lockfile
  192. - name: Download production files artifact
  193. uses: actions/download-artifact@v3
  194. with:
  195. name: Production Files
  196. - name: Extract procution files artifact
  197. run: |
  198. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  199. - name: Determine spec expression
  200. id: determine-spec-exp
  201. run: |
  202. SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.spec-group }}"`
  203. echo "::set-output name=value::$SPEC"
  204. - name: Copy dotenv file for ci
  205. working-directory: ./packages/app
  206. run: |
  207. cat config/ci/.env.local.for-ci >> .env.production.local
  208. - name: Copy dotenv file for automatic installation
  209. if: ${{ matrix.spec-group != '10' }}
  210. working-directory: ./packages/app
  211. run: |
  212. cat config/ci/.env.local.for-auto-install >> .env.production.local
  213. - name: Copy dotenv file for automatic installation with allowing guest mode
  214. if: ${{ matrix.spec-group == '21' }}
  215. working-directory: ./packages/app
  216. run: |
  217. cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
  218. - name: Cypress Run
  219. uses: cypress-io/github-action@v3
  220. with:
  221. browser: chrome
  222. working-directory: ./packages/app
  223. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  224. start: yarn server
  225. wait-on: 'http://localhost:3000'
  226. env:
  227. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi-vrt
  228. ELASTICSEARCH_URI: http://localhost:${{ job.services.elasticsearch.ports['9200'] }}/growi
  229. - name: Upload results
  230. if: always()
  231. uses: actions/upload-artifact@v3
  232. with:
  233. name: ${{ inputs.cypress-report-artifact-name }}
  234. path: |
  235. packages/app/test/cypress/screenshots
  236. packages/app/test/cypress/videos
  237. - name: Slack Notification
  238. uses: weseek/ghaction-slack-notification@master
  239. if: failure()
  240. with:
  241. type: ${{ job.status }}
  242. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  243. channel: '#ci'
  244. isCompactMode: true
  245. url: ${{ secrets.SLACK_WEBHOOK_URL }}