pre-commit 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. readonly reset=$(tput sgr0)
  3. readonly red=$(tput bold; tput setaf 1)
  4. readonly green=$(tput bold; tput setaf 2)
  5. exit_code=0
  6. echo -ne "Checking that it builds... "
  7. if ! OUT=$(make 2>&1); then
  8. echo
  9. echo "${red}${OUT}"
  10. exit_code=1
  11. else
  12. echo "${green}OK"
  13. fi
  14. echo "${reset}"
  15. # Check if changes to Godeps are reproducible...
  16. files=($(git diff --cached --name-only --diff-filter ACM | grep "Godeps"))
  17. if [[ "${#files[@]}" -ne 0 ]]; then
  18. echo -ne "Check if changes to Godeps are reproducible (this is pretty slow)..."
  19. if ! OUT=$("hack/verify-godeps.sh" 2>&1); then
  20. echo
  21. echo "${red}${OUT}"
  22. exit_code=1
  23. else
  24. echo "${green}OK"
  25. fi
  26. echo "${reset}"
  27. echo -ne "Check if Godep licenses are up to date..."
  28. if ! OUT=$("hack/verify-godep-licenses.sh" 2>&1); then
  29. echo
  30. echo "${red}${OUT}"
  31. exit_code=1
  32. else
  33. echo "${green}OK"
  34. fi
  35. echo "${reset}"
  36. fi
  37. echo -ne "Checking for files that need gofmt... "
  38. files_need_gofmt=()
  39. files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^third_party" -e "^vendor"))
  40. for file in "${files[@]}"; do
  41. # Check for files that fail gofmt.
  42. diff="$(git show ":${file}" | gofmt -s -d 2>&1)"
  43. if [[ -n "$diff" ]]; then
  44. files_need_gofmt+=("${file}")
  45. fi
  46. done
  47. if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then
  48. echo "${red}ERROR!"
  49. echo "Some files have not been gofmt'd. To fix these errors, "
  50. echo "copy and paste the following:"
  51. echo " gofmt -s -w ${files_need_gofmt[@]}"
  52. exit_code=1
  53. else
  54. echo "${green}OK"
  55. fi
  56. echo "${reset}"
  57. echo -ne "Checking for files that need boilerplate... "
  58. files=($(git diff --cached --name-only --diff-filter ACM))
  59. # We always make sure there is one file in the files list. Some tools check
  60. # the whole repo if they get no files, so in fact, this is much faster on
  61. # git commit --amend
  62. if [[ ${#files[@]} -eq 0 ]]; then
  63. files+=("README.md")
  64. fi
  65. out=($(hack/boilerplate/boilerplate.py "${files[@]}"))
  66. if [[ "${#out}" -ne 0 ]]; then
  67. echo "${red}ERROR!"
  68. echo "Some files are missing the required boilerplate header"
  69. echo "from hack/boilerplate/boilerplate.*.txt:"
  70. for f in "${out[@]}"; do
  71. echo " ${f}"
  72. done
  73. exit_code=1
  74. else
  75. echo "${green}OK"
  76. fi
  77. echo "${reset}"
  78. echo -ne "Checking for problems with flag names... "
  79. invalid_flag_lines=$(hack/verify-flags-underscore.py "${files[@]}")
  80. if [[ "${invalid_flag_lines:-}" != "" ]]; then
  81. echo "${red}ERROR!"
  82. echo "There appear to be problems with the following:"
  83. for line in "${invalid_flag_lines[@]}"; do
  84. echo " ${line}"
  85. done
  86. exit_code=1
  87. else
  88. echo "${green}OK"
  89. fi
  90. echo "${reset}"
  91. echo -ne "Checking for API descriptions... "
  92. files_need_description=()
  93. # Check API schema definitions for field descriptions
  94. for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do
  95. # Check for files with fields without description tags
  96. descriptionless=$(hack/verify-description.sh "${file}" > /dev/null; echo $?)
  97. if [[ "$descriptionless" -ne "0" ]]; then
  98. files_need_description+=("${file}")
  99. fi
  100. done
  101. if [[ "${#files_need_description[@]}" -ne 0 ]]; then
  102. echo "${red}ERROR!"
  103. echo "Some API files are missing the required field descriptions."
  104. echo "Add description tags to all non-inline fields in the following files:"
  105. for file in "${files_need_description[@]}"; do
  106. echo " ${file}"
  107. done
  108. exit_code=1
  109. else
  110. echo "${green}OK"
  111. fi
  112. echo "${reset}"
  113. echo -ne "Checking for docs that need updating... "
  114. if ! hack/verify-munge-docs.sh > /dev/null; then
  115. echo "${red}ERROR!"
  116. echo "Some docs are out of sync between CLI and markdown."
  117. echo "To regenerate docs, run:"
  118. echo " hack/update-munge-docs.sh"
  119. exit_code=1
  120. else
  121. echo "${green}OK"
  122. fi
  123. echo "${reset}"
  124. echo -ne "Checking for swagger type documentation that need updating... "
  125. if ! hack/verify-generated-swagger-docs.sh > /dev/null; then
  126. echo "${red}ERROR!"
  127. echo "Swagger type documentation needs to be updated."
  128. echo "To regenerate the spec, run:"
  129. echo " hack/update-generated-swagger-docs.sh"
  130. exit_code=1
  131. else
  132. echo "${green}OK"
  133. fi
  134. echo "${reset}"
  135. echo -ne "Checking for swagger spec that need updating... "
  136. if ! hack/verify-swagger-spec.sh > /dev/null; then
  137. echo "${red}ERROR!"
  138. echo "Swagger spec needs to be updated."
  139. echo "To regenerate the spec, run:"
  140. echo " hack/update-swagger-spec.sh"
  141. exit_code=1
  142. else
  143. echo "${green}OK"
  144. fi
  145. echo "${reset}"
  146. if [[ "${exit_code}" != 0 ]]; then
  147. echo "${red}Aborting commit${reset}"
  148. fi
  149. exit ${exit_code}
  150. # ex: ts=2 sw=2 et filetype=sh