mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
commit
99416947dc
@ -105,8 +105,7 @@ directory. This will keep you from accidentally committing non-gofmt'd go code.
|
|||||||
|
|
||||||
```
|
```
|
||||||
cd kubernetes/.git/hooks/
|
cd kubernetes/.git/hooks/
|
||||||
ln -s ../../hooks/prepare-commit-msg .
|
ln -s ../../hooks/pre-commit .
|
||||||
ln -s ../../hooks/commit-msg .
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Unit tests
|
## Unit tests
|
||||||
|
@ -130,7 +130,7 @@ kube::util::gen-doc() {
|
|||||||
# We do this in a tmpdir in case the dest has other non-autogenned files
|
# We do this in a tmpdir in case the dest has other non-autogenned files
|
||||||
# We don't want to include them in the list of gen'd files
|
# We don't want to include them in the list of gen'd files
|
||||||
local tmpdir="${KUBE_ROOT}/doc_tmp"
|
local tmpdir="${KUBE_ROOT}/doc_tmp"
|
||||||
mkdir "${tmpdir}"
|
mkdir -p "${tmpdir}"
|
||||||
# generate the new files
|
# generate the new files
|
||||||
${cmd} "${tmpdir}"
|
${cmd} "${tmpdir}"
|
||||||
# create the list of generated files
|
# create the list of generated files
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [[ "$(grep -c "COMMIT_BLOCKED" $1)" -gt 0 ]]; then
|
|
||||||
echo "FAILED: Unresolved errors - aborting the commit."
|
|
||||||
echo "The message of your attempted commit was:"
|
|
||||||
cat $1
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
@ -1,11 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
readonly reset=$(tput sgr0)
|
||||||
|
readonly red=$(tput bold; tput setaf 1)
|
||||||
|
readonly green=$(tput bold; tput setaf 2)
|
||||||
|
|
||||||
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
||||||
|
|
||||||
files_need_gofmt=()
|
exit_code=0
|
||||||
files_need_boilerplate=()
|
|
||||||
files_need_description=()
|
|
||||||
|
|
||||||
|
echo -ne "Checking for files that need gofmt... "
|
||||||
|
files_need_gofmt=()
|
||||||
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps"))
|
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps"))
|
||||||
for file in "${files[@]}"; do
|
for file in "${files[@]}"; do
|
||||||
# Check for files that fail gofmt.
|
# Check for files that fail gofmt.
|
||||||
@ -15,6 +19,19 @@ for file in "${files[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then
|
||||||
|
echo "${red}ERROR!"
|
||||||
|
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
|
||||||
|
echo "${green}OK"
|
||||||
|
fi
|
||||||
|
echo "${reset}"
|
||||||
|
|
||||||
|
echo -ne "Checking for files that need boilerplate... "
|
||||||
|
files_need_boilerplate=()
|
||||||
boiler="${KUBE_HOOKS_DIR}/boilerplate.py"
|
boiler="${KUBE_HOOKS_DIR}/boilerplate.py"
|
||||||
# Check for go files without the required boilerplate.
|
# Check for go files without the required boilerplate.
|
||||||
if [[ ${#files[@]} -gt 0 ]]; then
|
if [[ ${#files[@]} -gt 0 ]]; then
|
||||||
@ -33,6 +50,21 @@ if [[ ${#files} -gt 0 ]]; then
|
|||||||
files_need_boilerplate+=($("${boiler}" "py" "${files[@]}"))
|
files_need_boilerplate+=($("${boiler}" "py" "${files[@]}"))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; then
|
||||||
|
echo "${red}ERROR!"
|
||||||
|
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
|
||||||
|
echo "${green}OK"
|
||||||
|
fi
|
||||||
|
echo "${reset}"
|
||||||
|
|
||||||
|
echo -ne "Checking for API descriptions... "
|
||||||
|
files_need_description=()
|
||||||
# Check API schema definitions for field descriptions
|
# Check API schema definitions for field descriptions
|
||||||
for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do
|
for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do
|
||||||
# Check for files with fields without description tags
|
# Check for files with fields without description tags
|
||||||
@ -42,58 +74,29 @@ for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then
|
|
||||||
(
|
|
||||||
echo
|
|
||||||
echo "# *** ERROR: *** Some files have not been gofmt'd. To fix these"
|
|
||||||
echo "# errors, run gofmt -s -w <file>, or cut and paste the following:"
|
|
||||||
echo "# gofmt -s -w ${files_need_gofmt[@]}"
|
|
||||||
echo "#"
|
|
||||||
echo "# Your commit will be aborted unless you override this warning. To"
|
|
||||||
echo "# commit in spite of these format errors, delete the following line:"
|
|
||||||
echo "# COMMIT_BLOCKED_ON_GOFMT"
|
|
||||||
) >> $1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; then
|
|
||||||
(
|
|
||||||
echo
|
|
||||||
echo "# *** ERROR: *** Some files are missing the required boilerplate"
|
|
||||||
echo "# header from hooks/boilerplate.txt:"
|
|
||||||
for file in "${files_need_boilerplate[@]}"; do
|
|
||||||
echo "# ${file}"
|
|
||||||
done
|
|
||||||
echo "#"
|
|
||||||
echo "# Your commit will be aborted unless you fix these."
|
|
||||||
echo "# COMMIT_BLOCKED_ON_BOILERPLATE"
|
|
||||||
echo
|
|
||||||
) >> $1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${#files_need_description[@]}" -ne 0 ]]; then
|
if [[ "${#files_need_description[@]}" -ne 0 ]]; then
|
||||||
(
|
echo "${red}ERROR!"
|
||||||
echo
|
echo "Some API files are missing the required field descriptions."
|
||||||
echo "# *** ERROR: *** Some API files are missing the required field descriptions"
|
echo "Add description tags to all non-inline fields in the following files:"
|
||||||
echo "# Add description tags to all non-inline fields in the following files:"
|
for file in "${files_need_description[@]}"; do
|
||||||
for file in "${files_need_description[@]}"; do
|
echo " ${file}"
|
||||||
echo "# ${file}"
|
done
|
||||||
done
|
exit_code=1
|
||||||
echo "#"
|
else
|
||||||
echo "# Your commit will be aborted unless you fix these."
|
echo "${green}OK"
|
||||||
echo "# COMMIT_BLOCKED_ON_DESCRIPTION"
|
|
||||||
echo
|
|
||||||
) >> $1
|
|
||||||
fi
|
fi
|
||||||
|
echo "${reset}"
|
||||||
|
|
||||||
|
echo -ne "Checking for docs that need updating... "
|
||||||
if ! hack/verify-gendocs.sh > /dev/null; then
|
if ! hack/verify-gendocs.sh > /dev/null; then
|
||||||
(
|
echo "${red}ERROR!"
|
||||||
echo
|
echo "Some docs are out of sync between CLI and markdown."
|
||||||
echo "# *** ERROR: *** docs are out of sync between cli and markdown"
|
echo "To regenerate docs, run:"
|
||||||
echo "# run hack/run-gendocs.sh > docs/kubectl.md to regenerate"
|
echo " hack/run-gendocs.sh > docs/kubectl.md"
|
||||||
echo
|
exit_code=1
|
||||||
echo "#"
|
else
|
||||||
echo "# Your commit will be aborted unless you regenerate docs."
|
echo "${green}OK"
|
||||||
echo " COMMIT_BLOCKED_ON_GENDOCS"
|
|
||||||
echo
|
|
||||||
) >> $1
|
|
||||||
fi
|
fi
|
||||||
|
echo "${reset}"
|
||||||
|
|
||||||
|
exit $exit_code
|
Loading…
Reference in New Issue
Block a user