continuous-integration-run-tests.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if [ "$?" -ne "0" ]; then
  52. echo -e "💥 ${RED}$package${NC} doesn't have required code coverage 💥"
  53. failedCoveragePackages="$failedCoveragePackages $package"
  54. errorOccured=1
  55. fi
  56. fold_end "pkg-$package"
  57. done;
  58. if [ "$errorOccured" -eq "1" ]; then
  59. echo
  60. echo "---"
  61. echo
  62. if ! [[ -z $failedTestsPackages ]]; then
  63. echo -e "Following packages did not pass unit tests:${RED}$failedTestsPackages${NC}"
  64. fi
  65. if ! [[ -z $failedCoveragePackages ]]; then
  66. echo -e "Following packages did not provide required code coverage:${RED}$failedCoveragePackages${NC}"
  67. fi
  68. echo
  69. exit 1 # Will break the CI build
  70. fi