reusable-app-prod.yml 8.9 KB

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