reusable-app-prod.yml 8.9 KB

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