Skip to content

Commit 1f5dff7

Browse files
committed
Fix verify-generated-swagger-docs script
1 parent f04ce29 commit 1f5dff7

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

hack/.shellcheck_failures

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
./hack/update-generated-protobuf.sh
9999
./hack/update-generated-runtime-dockerized.sh
100100
./hack/update-generated-runtime.sh
101-
./hack/update-generated-swagger-docs.sh
102101
./hack/update-godep-licenses.sh
103102
./hack/update-gofmt.sh
104103
./hack/update-openapi-spec.sh
@@ -120,7 +119,6 @@
120119
./hack/verify-generated-pod-resources.sh
121120
./hack/verify-generated-protobuf.sh
122121
./hack/verify-generated-runtime.sh
123-
./hack/verify-generated-swagger-docs.sh
124122
./hack/verify-golint.sh
125123
./hack/verify-govet.sh
126124
./hack/verify-import-boss.sh

hack/update-generated-swagger-docs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ set -o errexit
2323
set -o nounset
2424
set -o pipefail
2525

26-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
26+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2727
source "${KUBE_ROOT}/hack/lib/init.sh"
2828
source "${KUBE_ROOT}/hack/lib/swagger.sh"
2929

3030
kube::golang::setup_env
3131

32-
GROUP_VERSIONS=(meta/v1 meta/v1beta1 ${KUBE_AVAILABLE_GROUP_VERSIONS})
32+
IFS=" " read -r -a GROUP_VERSIONS <<< "meta/v1 meta/v1beta1 ${KUBE_AVAILABLE_GROUP_VERSIONS}"
3333

3434
# To avoid compile errors, remove the currently existing files.
3535
for group_version in "${GROUP_VERSIONS[@]}"; do

hack/verify-generated-swagger-docs.sh

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
21+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2222
source "${KUBE_ROOT}/hack/lib/init.sh"
2323

2424
kube::golang::setup_env
@@ -38,29 +38,57 @@ if [[ ! -x "$genswaggertypedocs" ]]; then
3838
exit 1
3939
fi
4040

41-
DIFFROOT="${KUBE_ROOT}/pkg"
42-
TMP_DIFFROOT="${KUBE_ROOT}/_tmp/pkg"
43-
_tmp="${KUBE_ROOT}/_tmp"
44-
45-
cleanup() {
46-
rm -rf "${_tmp}"
41+
_tmpdir="$(kube::realpath "$(mktemp -d -t swagger-docs.XXXXXX)")"
42+
function swagger_cleanup {
43+
rm -rf "${_tmpdir}"
4744
}
48-
trap "cleanup" EXIT SIGINT
45+
kube::util::trap_add swagger_cleanup EXIT
46+
47+
# Copy the contents of the kube directory into the nice clean place
48+
_kubetmp="${_tmpdir}/src/k8s.io"
49+
mkdir -p "${_kubetmp}"
50+
# should create ${_kubetmp}/kubernetes
51+
git archive --format=tar --prefix=kubernetes/ "$(git write-tree)" | (cd "${_kubetmp}" && tar xf -)
52+
_kubetmp="${_kubetmp}/kubernetes"
53+
# Do all our work in the new GOPATH
54+
export GOPATH="${_tmpdir}"
4955

50-
cleanup
56+
find_files() {
57+
find . -not \( \
58+
\( \
59+
-wholename './output' \
60+
-o -wholename './.git' \
61+
-o -wholename './_output' \
62+
-o -wholename './_gopath' \
63+
-o -wholename './release' \
64+
-o -wholename './target' \
65+
-o -wholename '*/third_party/*' \
66+
-o -wholename '*/vendor/*' \
67+
-o -wholename './staging/src/k8s.io/client-go/*vendor/*' \
68+
\) -prune \
69+
\) -name 'types_swagger_doc_generated.go'
70+
}
71+
while IFS=$'\n' read -r line; do TARGET_FILES+=("$line"); done < <(find_files)
5172

52-
mkdir -p "${TMP_DIFFROOT}"
53-
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}/"
73+
pushd "${_kubetmp}" > /dev/null 2>&1
74+
# Update the generated swagger docs
75+
hack/update-generated-swagger-docs.sh
76+
popd > /dev/null 2>&1
5477

55-
"${KUBE_ROOT}/hack/update-generated-swagger-docs.sh"
56-
echo "diffing ${DIFFROOT} against freshly generated swagger type documentation"
5778
ret=0
58-
diff --exclude=".import-restrictions" -Naupr -I 'Auto generated by' "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
59-
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}/"
60-
if [[ $ret -eq 0 ]]
61-
then
62-
echo "${DIFFROOT} up to date."
63-
else
64-
echo "${DIFFROOT} is out of date. Please run hack/update-generated-swagger-docs.sh"
65-
exit 1
66-
fi
79+
80+
pushd "${KUBE_ROOT}" > /dev/null 2>&1
81+
# Test for diffs
82+
_output=""
83+
for file in ${TARGET_FILES[*]}; do
84+
_output="${_output}$(diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${file}" "${_kubetmp}/${file}")" || ret=1
85+
done
86+
87+
if [[ ${ret} -gt 0 ]]; then
88+
echo "Generated swagger type documentation is out of date:" >&2
89+
echo "${_output}" >&2
90+
exit ${ret}
91+
fi
92+
popd > /dev/null 2>&1
93+
94+
echo "Generated swagger type documentation up to date."

0 commit comments

Comments
 (0)