forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·151 lines (134 loc) · 4.31 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/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")")"
exit_code=0
echo -ne "Checking that it builds... "
if ! OUT=$("hack/build-go.sh" 2>&1); then
echo
echo "${red}${OUT}"
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"
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"))
for file in "${files[@]}"; do
# Check for files that fail gofmt.
diff="$(git show ":${file}" | gofmt -s -d 2>&1)"
if [[ -n "$diff" ]]; then
files_need_gofmt+=("${file}")
fi
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"
# 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
# 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
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
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
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
echo "${red}ERROR!"
echo "Some API files are missing the required field descriptions."
echo "Add description tags to all non-inline fields in the following files:"
for file in "${files_need_description[@]}"; do
echo " ${file}"
done
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"
echo -ne "Checking for docs that need updating... "
if ! hack/verify-gendocs.sh > /dev/null; then
echo "${red}ERROR!"
echo "Some docs are out of sync between CLI and markdown."
echo "To regenerate docs, run:"
echo " hack/run-gendocs.sh"
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"
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}"
echo -ne "Checking for deep-copies that need updating... "
if ! hack/verify-generated-deep-copies.sh > /dev/null; then
echo "${red}ERROR!"
echo "Some deep-copy functions need regeneration."
echo "To regenerate deep-copies, run:"
echo " hack/update-generated-deep-copies.sh"
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"
echo -ne "Checking for swagger spec that need updating... "
if ! hack/verify-swagger-spec.sh > /dev/null; then
echo "${red}ERROR!"
echo "Swagger spec needs to be updated."
echo "To regenerate the spec, run:"
echo " hack/update-swagger-spec.sh"
exit_code=1
else
echo "${green}OK"
fi
echo "${reset}"
if [[ "${exit_code}" != 0 ]]; then
echo "${red}Aborting commit${reset}"
fi
exit ${exit_code}