elvis-check.sh 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. set -euo pipefail
  3. ELVIS_VERSION='1.0.0-emqx-1'
  4. base=${GITHUB_BASE_REF:-$1}
  5. elvis_version="${2:-$ELVIS_VERSION}"
  6. echo "elvis -v: $elvis_version"
  7. echo "git diff base: $base"
  8. if [ ! -f ./elvis ] || [ "$(./elvis -v | grep -oE '[1-9]+\.[0-9]+\.[0-9]+\-emqx-[0-9]+')" != "$elvis_version" ]; then
  9. curl -fLO "https://github.com/emqx/elvis/releases/download/$elvis_version/elvis"
  10. chmod +x ./elvis
  11. fi
  12. git fetch origin "$base"
  13. git_diff() {
  14. git diff --name-only origin/"$base"...HEAD
  15. }
  16. bad_file_count=0
  17. for file in $(git_diff); do
  18. if [ ! -f "$file" ]; then
  19. # file is deleted, skip
  20. continue
  21. fi
  22. if [[ $file != *.erl ]]; then
  23. # not .erl file
  24. continue
  25. fi
  26. if ! ./elvis rock "$file" -c elvis.config; then
  27. bad_file_count=$(( bad_file_count + 1))
  28. fi
  29. done
  30. if [ $bad_file_count -gt 0 ]; then
  31. echo "elvis: $bad_file_count errors"
  32. exit 1
  33. fi