sanity.sh 1.4 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. printf "\033[0;31mFAILED\033[0m\n"
  26. echo "=== Captured output:"
  27. cat "$log"
  28. echo "==="
  29. fi
  30. }
  31. function check_license_headers() {
  32. run_logged "Checking license headers" "$HERE/license-check.sh"
  33. }
  34. function check_formatting() {
  35. hash swiftformat 2> /dev/null || { printf "\033[0;31mERROR\033[0m swiftformat must be installed (see: https://github.com/nicklockwood/SwiftFormat)\n"; exit 1; }
  36. run_logged "Checking formatting" "swiftformat --lint $HERE/.."
  37. }
  38. check_license_headers
  39. # We won't run this just yet.
  40. # check_formatting