8
0
Pārlūkot izejas kodu

Internal: Added monorepo CI/CC script.

Marek Lewandowski 5 gadi atpakaļ
vecāks
revīzija
8025035b0e
3 mainītis faili ar 82 papildinājumiem un 6 dzēšanām
  1. 1 6
      .travis.yml
  2. 2 0
      package.json
  3. 79 0
      scripts/codecov-run-tests.sh

+ 1 - 6
.travis.yml

@@ -12,16 +12,11 @@ node_js:
 cache:
 - node_modules
 before_install:
-- export START_TIME=$( date +%s )
 - npm i -g yarn
 install:
-- yarn add mrgit --ignore-workspace-root-check
-- mrgit sync --resolver-url-template="https://github.com/\${ path }.git"
-- git checkout package.json yarn.lock
-- rm -rf node_modules
 - yarn install
 script:
-- yarn run test --reporter=dots --production
+- ./scripts/codecov-run-tests.sh
 - yarn run docs:api --validate-only
 - 'if [ $TRAVIS_TEST_RESULT -eq 0 ]; then
     travis_wait 30 yarn run docs:build-and-publish-nightly;

+ 2 - 0
package.json

@@ -88,6 +88,7 @@
     "@ckeditor/ckeditor5-track-changes": "^18.0.0",
     "@wiris/mathtype-ckeditor5": "^7.19.0",
     "babel-standalone": "^6.26.0",
+    "codecov": "^3.6.5",
     "css-loader": "^1.0.0",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^2.0.0",
@@ -98,6 +99,7 @@
     "mini-css-extract-plugin": "^0.4.0",
     "minimatch": "^3.0.4",
     "mrgit": "^1.0.0",
+    "nyc": "^15.0.1",
     "postcss-loader": "^3.0.0",
     "progress-bar-webpack-plugin": "^1.12.1",
     "raw-loader": "^3.1.0",

+ 79 - 0
scripts/codecov-run-tests.sh

@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+# For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+
+packages=$(ls packages -1 | sed -e 's#^ckeditor5\?-\(.\+\)$#\1#')
+
+errorOccured=0
+
+rm -r -f _coverage
+mkdir _coverage
+rm -r -f .nyc_output
+mkdir .nyc_output
+
+failedTestsPackages=""
+failedCoveragePackages=""
+
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+NC='\033[0m'
+
+for package in $packages; do
+
+  echo -e "Running tests for: ${GREEN}$package${NC}"
+
+  # Ignoring stdout for readability. Stderro is ignored too, because we get regular "(node:14303) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead".
+  testsOutput=$(yarn run test -f $package --reporter=dots --production --coverage 2>&1 /dev/null)
+
+  if [ "$?" -ne "0" ]; then
+    echo "$testsOutput"
+    echo
+
+    echo -e "💥 ${RED}$package${NC} failed to pass unit tests 💥"
+    failedTestsPackages="$failedTestsPackages $package"
+    errorOccured=1
+  fi
+
+  mkdir _coverage/$package
+
+  cp coverage/*/coverage-final.json .nyc_output
+
+  # Keep a copy that will be used for merging to make a combined report.
+  cp .nyc_output/coverage-final.json _coverage/coverage-$package.json
+
+  npx nyc check-coverage --branches 100 --functions 100 --lines 100 --statements 100
+
+  if [ "$?" -ne "0" ]; then
+    echo -e "💥 ${RED}$package${NC} doesn't have required code coverage 💥"
+    failedCoveragePackages="$failedCoveragePackages $package"
+    errorOccured=1
+  fi
+done;
+
+echo "Creating a combined code coverage report"
+
+# Combined file will be used for full coverage (as if yarn run test -c was run).
+npx nyc merge _coverage .nyc_output/coverage-final.json
+
+# You could attempt to check-coverage here too, but since each subpackage had a correct CC there's no point in doing this
+# for combined result.
+
+codecov -f .nyc_output/coverage-final.json
+
+if [ "$errorOccured" -eq "1" ]; then
+  echo
+  echo "---"
+  echo
+
+  if ! [[ -z $failedTestsPackages ]]; then
+    echo -e "Following packages did not pass unit tests:${RED}$failedTestsPackages${NC}"
+  fi
+
+  if ! [[ -z $failedCoveragePackages ]]; then
+    echo -e "Following packages did not provide required code coverage:${RED}$failedCoveragePackages${NC}"
+  fi
+
+  echo
+  exit 1 # Will break the CI build
+fi