reusable-app-prod.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. checkout-ref:
  9. type: string
  10. default: ${{ github.head_ref }}
  11. skip-launching-test:
  12. type: boolean
  13. jobs:
  14. build-prod:
  15. runs-on: ubuntu-latest
  16. outputs:
  17. PROD_FILES: ${{ steps.archive-prod-files.outputs.file }}
  18. steps:
  19. - uses: actions/checkout@v2
  20. with:
  21. ref: ${{ inputs.checkout-ref }}
  22. - uses: actions/setup-node@v2
  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@v2
  30. with:
  31. path: |
  32. **/node_modules
  33. key: node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  34. restore-keys: |
  35. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  36. - name: lerna bootstrap
  37. run: |
  38. npx lerna bootstrap -- --frozen-lockfile
  39. - name: Remove unnecessary packages
  40. run: |
  41. rm -rf packages/slackbot-proxy
  42. - name: Build
  43. run: |
  44. yarn lerna run build
  45. env:
  46. ANALYZE_BUNDLE_SIZE: 1
  47. - name: Archive production files
  48. id: archive-prod-files
  49. run: |
  50. tar -cf production.tar packages/**/dist packages/app/public
  51. echo ::set-output name=file::production.tar
  52. - name: Upload production files as artifact
  53. uses: actions/upload-artifact@v2
  54. with:
  55. name: Production Files
  56. path: ${{ steps.archive-prod-files.outputs.file }}
  57. - name: Upload report as artifact
  58. uses: actions/upload-artifact@v2
  59. with:
  60. name: Bundle Analyzing Report
  61. path: packages/app/report/bundle-analyzer.html
  62. - name: Slack Notification
  63. uses: weseek/ghaction-slack-notification@master
  64. if: failure()
  65. with:
  66. type: ${{ job.status }}
  67. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  68. channel: '#ci'
  69. isCompactMode: true
  70. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  71. launch-prod:
  72. needs: [build-prod]
  73. runs-on: ubuntu-latest
  74. if: ${{ !inputs.skip-launching-test }}
  75. services:
  76. mongodb:
  77. image: mongo:4.4
  78. ports:
  79. - 27017/tcp
  80. mongodb36:
  81. image: mongo:3.6
  82. ports:
  83. - 27017/tcp
  84. steps:
  85. - uses: actions/checkout@v2
  86. with:
  87. ref: ${{ inputs.checkout-ref }}
  88. - uses: actions/setup-node@v2
  89. with:
  90. node-version: ${{ inputs.node-version }}
  91. cache: 'yarn'
  92. cache-dependency-path: '**/yarn.lock'
  93. - name: Get Date
  94. id: get-date
  95. run: |
  96. echo "::set-output name=dateYmdHM::$(/bin/date -u "+%Y%m%d%H%M")"
  97. echo "::set-output name=dateYm::$(/bin/date -u "+%Y%m")"
  98. - name: Cache/Restore node_modules (not reused)
  99. id: cache-dependencies
  100. uses: actions/cache@v2
  101. with:
  102. path: |
  103. **/node_modules
  104. key: node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYmdHM }}
  105. restore-keys: |
  106. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  107. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  108. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-${{ steps.get-date.outputs.dateYm }}
  109. node_modules-build-prod-${{ runner.OS }}-node${{ inputs.node-version }}-
  110. - name: Remove unnecessary packages
  111. run: |
  112. rm -rf packages/slackbot-proxy
  113. - name: lerna bootstrap --production
  114. run: |
  115. npx lerna bootstrap -- --production
  116. - name: Download production files artifact
  117. uses: actions/download-artifact@v2
  118. with:
  119. name: Production Files
  120. - name: Extract procution files artifact
  121. run: |
  122. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  123. - name: yarn server:ci
  124. working-directory: ./packages/app
  125. run: |
  126. cp config/ci/.env.local.for-ci .env.production.local
  127. yarn server:ci
  128. env:
  129. MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi
  130. - name: yarn server:ci with MongoDB 3.6
  131. working-directory: ./packages/app
  132. run: |
  133. cp config/ci/.env.local.for-ci .env.production.local
  134. yarn server:ci
  135. env:
  136. MONGO_URI: mongodb://localhost:${{ job.services.mongodb36.ports['27017'] }}/growi
  137. - name: Slack Notification
  138. uses: weseek/ghaction-slack-notification@master
  139. if: failure()
  140. with:
  141. type: ${{ job.status }}
  142. job_name: '*Node CI for growi - build-prod (${{ inputs.node-version }})*'
  143. channel: '#ci'
  144. isCompactMode: true
  145. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  146. run-cypress:
  147. needs: [build-prod]
  148. runs-on: ubuntu-latest
  149. container: cypress/base:14.18.1
  150. strategy:
  151. fail-fast: false
  152. matrix:
  153. # List string expressions that is comma separated ids of tests in "test/cypress/integration"
  154. spec-group: ['1', '2']
  155. services:
  156. mongodb:
  157. image: mongo:4.4
  158. ports:
  159. - 27017/tcp
  160. steps:
  161. - uses: actions/checkout@v2
  162. with:
  163. ref: ${{ inputs.checkout-ref }}
  164. - uses: actions/setup-node@v2
  165. with:
  166. node-version: ${{ inputs.node-version }}
  167. cache: 'yarn'
  168. cache-dependency-path: '**/yarn.lock'
  169. # workaround by https://github.com/cypress-io/github-action/issues/407
  170. - name: Setup yarn cache settings
  171. run: yarn config set cache-folder ~/.cache/yarn
  172. - name: Cache/Restore node_modules
  173. uses: actions/cache@v2
  174. with:
  175. path: |
  176. **/node_modules
  177. ~/.cache/Cypress
  178. key: node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  179. restore-keys: |
  180. node_modules-and-cypress-bin-${{ runner.OS }}-node${{ inputs.node-version }}
  181. - name: lerna bootstrap
  182. run: |
  183. npx lerna bootstrap -- --frozen-lockfile
  184. - name: Download production files artifact
  185. uses: actions/download-artifact@v2
  186. with:
  187. name: Production Files
  188. - name: Extract procution files artifact
  189. run: |
  190. tar -xf ${{ needs.build-prod.outputs.PROD_FILES }}
  191. - name: Determine spec expression
  192. id: determine-spec-exp
  193. run: |
  194. SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.spec-group }}"`
  195. echo "::set-output name=value::$SPEC"
  196. - name: Cypress Run
  197. uses: cypress-io/github-action@v2
  198. with:
  199. working-directory: ./packages/app
  200. install: false
  201. spec: '${{ steps.determine-spec-exp.outputs.value }}'
  202. build: |
  203. cp config/ci/.env.local.for-ci .env.production.local
  204. start: yarn server
  205. wait-on: 'http://localhost:3000'
  206. env:
  207. MONGO_URI: mongodb://mongodb:27017/growi-vrt
  208. - name: Upload results
  209. if: always()
  210. uses: actions/upload-artifact@v2
  211. with:
  212. name: Cypress Report
  213. path: |
  214. packages/app/test/cypress/screenshots
  215. packages/app/test/cypress/videos
  216. - name: Slack Notification
  217. uses: weseek/ghaction-slack-notification@master
  218. if: failure()
  219. with:
  220. type: ${{ job.status }}
  221. job_name: '*Node CI for growi - run-cypress (${{ inputs.node-version }})*'
  222. channel: '#ci'
  223. isCompactMode: true
  224. url: ${{ secrets.SLACK_WEBHOOK_URL }}
  225. run-reg-suit:
  226. needs: [run-cypress]
  227. if: always()
  228. # use secrets for "VRT" environment
  229. # https://github.com/weseek/growi/settings/environments/376165508/edit
  230. environment: VRT
  231. runs-on: ubuntu-latest
  232. steps:
  233. - uses: actions/checkout@v2
  234. with:
  235. ref: ${{ inputs.checkout-ref }}
  236. fetch-depth: 0
  237. - uses: actions/setup-node@v2
  238. with:
  239. node-version: ${{ inputs.node-version }}
  240. cache: 'yarn'
  241. cache-dependency-path: '**/yarn.lock'
  242. - name: Cache/Restore node_modules
  243. uses: actions/cache@v2
  244. with:
  245. path: |
  246. **/node_modules
  247. key: node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}
  248. restore-keys: |
  249. node_modules-${{ runner.OS }}-node${{ inputs.node-version }}-
  250. - name: lerna bootstrap
  251. run: |
  252. npx lerna bootstrap -- --frozen-lockfile
  253. - name: Download screenshots taken by cypress
  254. uses: actions/download-artifact@v2
  255. with:
  256. name: Cypress Report
  257. path: packages/app/test/cypress
  258. - name: debug
  259. run: |
  260. ls -R packages/app/test/cypress
  261. - name: Run reg-suit
  262. working-directory: ./packages/app
  263. run: |
  264. yarn reg:run
  265. env:
  266. REG_NOTIFY_GITHUB_PLUGIN_CLIENTID: ${{ secrets.REG_NOTIFY_GITHUB_PLUGIN_CLIENTID }}
  267. AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  268. AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  269. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  270. - name: Slack Notification
  271. uses: weseek/ghaction-slack-notification@master
  272. if: failure()
  273. with:
  274. type: ${{ job.status }}
  275. job_name: '*Node CI for growi - run-reg-suit (${{ inputs.node-version }})*'
  276. channel: '#ci'
  277. isCompactMode: true
  278. url: ${{ secrets.SLACK_WEBHOOK_URL }}