sanity.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # Copyright 2020, gRPC Authors All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -eu
  16. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  17. function run_logged() {
  18. local message=$1
  19. local command=$2
  20. log=$(mktemp)
  21. printf '==> %s ... ' "$message"
  22. if $command > "$log" 2>&1; then
  23. printf "\033[0;32mOK\033[0m\n"
  24. else
  25. errors=$(( errors + 1))
  26. printf "\033[0;31mFAILED\033[0m\n"
  27. echo "=== Captured output:"
  28. cat "$log"
  29. echo "==="
  30. fi
  31. }
  32. function check_license_headers() {
  33. run_logged "Checking license headers" "$here/license-check.sh"
  34. }
  35. function check_formatting() {
  36. run_logged "Checking formatting" "$here/format.sh -l"
  37. }
  38. errors=0
  39. check_license_headers
  40. check_formatting
  41. exit $errors