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