reusable-app-prod.yml 9.5 KB

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