2014-06-06 23:40:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-05-13 19:59:04 +00:00
|
|
|
readonly reset=$(tput sgr0)
|
|
|
|
readonly red=$(tput bold; tput setaf 1)
|
|
|
|
readonly green=$(tput bold; tput setaf 2)
|
|
|
|
|
2014-06-23 18:34:44 +00:00
|
|
|
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
exit_code=0
|
2015-05-01 18:57:03 +00:00
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
echo -ne "Checking for files that need gofmt... "
|
|
|
|
files_need_gofmt=()
|
2015-05-01 18:57:03 +00:00
|
|
|
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps"))
|
|
|
|
for file in "${files[@]}"; do
|
2014-06-24 22:01:08 +00:00
|
|
|
# Check for files that fail gofmt.
|
2014-06-13 05:03:00 +00:00
|
|
|
diff="$(git show ":${file}" | gofmt -s -d)"
|
2014-06-06 23:40:48 +00:00
|
|
|
if [[ -n "$diff" ]]; then
|
2014-11-20 00:05:55 +00:00
|
|
|
files_need_gofmt+=("${file}")
|
2014-06-06 23:40:48 +00:00
|
|
|
fi
|
2014-06-26 00:11:48 +00:00
|
|
|
done
|
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${red}ERROR!"
|
2015-05-13 05:47:24 +00:00
|
|
|
echo "Some files have not been gofmt'd. To fix these errors, "
|
|
|
|
echo "cut and paste the following:"
|
|
|
|
echo " gofmt -s -w ${files_need_gofmt[@]}"
|
|
|
|
exit_code=1
|
|
|
|
else
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${green}OK"
|
2015-05-13 05:47:24 +00:00
|
|
|
fi
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${reset}"
|
2015-05-13 05:47:24 +00:00
|
|
|
|
|
|
|
echo -ne "Checking for files that need boilerplate... "
|
|
|
|
files_need_boilerplate=()
|
2015-05-01 18:57:03 +00:00
|
|
|
boiler="${KUBE_HOOKS_DIR}/boilerplate.py"
|
|
|
|
# Check for go files without the required boilerplate.
|
|
|
|
if [[ ${#files[@]} -gt 0 ]]; then
|
|
|
|
files_need_boilerplate+=($("${boiler}" "go" "${files[@]}"))
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for sh files without the required boilerplate.
|
|
|
|
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.sh" | grep -v -e "third_party" -e "Godeps"))
|
|
|
|
if [[ ${#files[@]} -gt 0 ]]; then
|
|
|
|
files_need_boilerplate+=($("${boiler}" "sh" "${files[@]}"))
|
|
|
|
fi
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2015-05-01 21:25:49 +00:00
|
|
|
# Check for py files without the required boilerplate.
|
|
|
|
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.py" | grep -v -e "third_party" -e "Godeps"))
|
|
|
|
if [[ ${#files} -gt 0 ]]; then
|
|
|
|
files_need_boilerplate+=($("${boiler}" "py" "${files[@]}"))
|
|
|
|
fi
|
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; then
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${red}ERROR!"
|
2015-05-13 05:47:24 +00:00
|
|
|
echo "Some files are missing the required boilerplate header"
|
|
|
|
echo "from hooks/boilerplate.txt:"
|
|
|
|
for file in "${files_need_boilerplate[@]}"; do
|
|
|
|
echo " ${file}"
|
|
|
|
done
|
|
|
|
exit_code=1
|
|
|
|
else
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${green}OK"
|
2015-05-13 05:47:24 +00:00
|
|
|
fi
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${reset}"
|
2015-05-13 05:47:24 +00:00
|
|
|
|
|
|
|
echo -ne "Checking for API descriptions... "
|
|
|
|
files_need_description=()
|
2014-11-20 00:05:55 +00:00
|
|
|
# Check API schema definitions for field descriptions
|
2015-05-01 18:10:50 +00:00
|
|
|
for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do
|
2014-11-20 00:05:55 +00:00
|
|
|
# Check for files with fields without description tags
|
|
|
|
descriptionless=$("${KUBE_HOOKS_DIR}/description.sh" "${file}")
|
|
|
|
if [[ "$descriptionless" -eq "0" ]]; then
|
|
|
|
files_need_description+=("${file}")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "${#files_need_description[@]}" -ne 0 ]]; then
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${red}ERROR!"
|
2015-05-13 05:47:24 +00:00
|
|
|
echo "Some API files are missing the required field descriptions."
|
|
|
|
echo "Add description tags to all non-inline fields in the following files:"
|
2015-05-13 04:59:44 +00:00
|
|
|
for file in "${files_need_description[@]}"; do
|
2015-05-13 05:47:24 +00:00
|
|
|
echo " ${file}"
|
2015-05-13 04:59:44 +00:00
|
|
|
done
|
2015-05-13 05:47:24 +00:00
|
|
|
exit_code=1
|
|
|
|
else
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${green}OK"
|
2014-11-20 00:05:55 +00:00
|
|
|
fi
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${reset}"
|
2015-01-15 05:27:13 +00:00
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
echo -ne "Checking for docs that need updating... "
|
2015-01-15 05:27:13 +00:00
|
|
|
if ! hack/verify-gendocs.sh > /dev/null; then
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${red}ERROR!"
|
2015-05-13 05:47:24 +00:00
|
|
|
echo "Some docs are out of sync between CLI and markdown."
|
|
|
|
echo "To regenerate docs, run:"
|
2015-05-21 17:01:34 +00:00
|
|
|
echo " hack/run-gendocs.sh"
|
2015-05-13 05:47:24 +00:00
|
|
|
exit_code=1
|
|
|
|
else
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${green}OK"
|
2015-01-15 05:27:13 +00:00
|
|
|
fi
|
2015-05-13 19:59:04 +00:00
|
|
|
echo "${reset}"
|
2015-05-13 04:59:44 +00:00
|
|
|
|
2015-05-19 15:47:03 +00:00
|
|
|
echo -ne "Checking for conversions that need updating... "
|
|
|
|
if ! hack/verify-generated-conversions.sh > /dev/null; then
|
|
|
|
echo "${red}ERROR!"
|
|
|
|
echo "Some conversions functions need regeneration."
|
|
|
|
echo "To regenerate conversions, run:"
|
|
|
|
echo " hack/update-generated-conversions.sh"
|
|
|
|
exit_code=1
|
|
|
|
else
|
|
|
|
echo "${green}OK"
|
|
|
|
fi
|
|
|
|
echo "${reset}"
|
|
|
|
|
2015-05-13 05:47:24 +00:00
|
|
|
exit $exit_code
|