continuous-integration-run-tests.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. # For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. packages=$(ls packages -1 | sed -e 's#^ckeditor5\?-\(.\+\)$#\1#')
  5. errorOccured=0
  6. failedTestsPackages=""
  7. failedCoveragePackages=""
  8. RED='\033[0;31m'
  9. NC='\033[0m'
  10. # Travis functions inspired by https://github.com/travis-ci/travis-rubies/blob/a10ba31e3f508650204017332a608ef9bce2c733/build.sh.
  11. function travis_nanoseconds() {
  12. local cmd="date"
  13. local format="+%s%N"
  14. local os=$(uname)
  15. if hash gdate > /dev/null 2>&1; then
  16. cmd="gdate" # use gdate if available
  17. elif [[ "$os" = Darwin ]]; then
  18. format="+%s000000000" # fallback to second precision on darwin (does not support %N)
  19. fi
  20. $cmd -u $format
  21. }
  22. travis_time_start() {
  23. travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
  24. travis_start_time=$(travis_nanoseconds)
  25. echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
  26. }
  27. travis_time_finish() {
  28. local result=$?
  29. travis_end_time=$(travis_nanoseconds)
  30. local duration=$(($travis_end_time-$travis_start_time))
  31. echo -en "\ntravis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
  32. return $result
  33. }
  34. fold_start() {
  35. echo -e "travis_fold:start:$1\033[33;1m$2\033[0m"
  36. travis_time_start
  37. }
  38. fold_end() {
  39. travis_time_finish
  40. echo -e "\ntravis_fold:end:$1\n"
  41. }
  42. for package in $packages; do
  43. fold_start "pkg-$package" "Testing $package${NC}"
  44. yarn run test -f $package --reporter=dots --production --coverage
  45. if [ "$?" -ne "0" ]; then
  46. echo
  47. echo -e "💥 ${RED}$package${NC} failed to pass unit tests 💥"
  48. failedTestsPackages="$failedTestsPackages $package"
  49. errorOccured=1
  50. fi
  51. npx nyc check-coverage --branches 100 --functions 100 --lines 100 --statements 100
  52. if [ "$?" -ne "0" ]; then
  53. echo -e "💥 ${RED}$package${NC} doesn't have required code coverage 💥"
  54. failedCoveragePackages="$failedCoveragePackages $package"
  55. errorOccured=1
  56. fi
  57. fold_end "pkg-$package"
  58. done;
  59. if [ "$errorOccured" -eq "1" ]; then
  60. echo
  61. echo "---"
  62. echo
  63. if ! [[ -z $failedTestsPackages ]]; then
  64. echo -e "Following packages did not pass unit tests:${RED}$failedTestsPackages${NC}"
  65. fi
  66. if ! [[ -z $failedCoveragePackages ]]; then
  67. echo -e "Following packages did not provide required code coverage:${RED}$failedCoveragePackages${NC}"
  68. fi
  69. echo
  70. exit 1 # Will break the CI build
  71. fi