reusable-app-prod.yml 9.6 KB

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