Filter munges out during doc generation

This allows us to apply content-mutating munges to generated files and nothave
the verifier flag them as needing regeneration later.
This commit is contained in:
Tim Hockin 2015-07-11 15:57:52 -07:00
parent ad8f8731b6
commit 06a6623a70
3 changed files with 19 additions and 11 deletions

View File

@ -143,11 +143,19 @@ kube::util::gen-doc() {
link=$(kube::util::analytics-link "${path}")
echo -e "\n${link}" >> "${tmpdir}/${file}"
fi
# remove all old generated files from the destination
if [[ -e "${tmpdir}/${file}" && -n "${skipprefix}" ]]; then
# Remove all old generated files from the destination
if [[ -e "${tmpdir}/${file}" ]]; then
local original generated
original=$(grep -v "^${skipprefix}" "${dest}/${file}") || :
generated=$(grep -v "^${skipprefix}" "${tmpdir}/${file}") || :
# Filter all munges from original content.
original=$(cat "${dest}/${file}" | sed '/^<!-- BEGIN MUNGE:.*/,/^<!-- END MUNGE:.*/d')
generated=$(cat "${tmpdir}/${file}")
# If this function was asked to filter lines with a prefix, do so.
if [[ -n "${skipprefix}" ]]; then
original=$(echo "${original}" | grep -v "^${skipprefix}" || :)
generated=$(echo "${generated}" | grep -v "^${skipprefix}" || :)
fi
# By now, the contents should be normalized and stripped of any
# auto-managed content.
if [[ "${original}" == "${generated}" ]]; then
# actual contents same, overwrite generated with original.
mv "${dest}/${file}" "${tmpdir}/${file}"

View File

@ -40,6 +40,11 @@ if [[ ! -x "$gendocs" || ! -x "$genman" || ! -x "$genbashcomp" || ! -x "$mungedo
exit 1
fi
kube::util::gen-doc "${gendocs}" "${KUBE_ROOT}/docs/" '###### Auto generated by spf13/cobra'
kube::util::gen-doc "${genman}" "${KUBE_ROOT}/docs/man/man1"
kube::util::gen-doc "${genbashcomp}" "${KUBE_ROOT}/contrib/completions/bash/"
kube::util::gen-analytics "${KUBE_ROOT}"
"${mungedocs}" "--root-dir=${KUBE_ROOT}/docs/"
ret=$?
if [[ $ret -eq 1 ]]; then
@ -50,9 +55,4 @@ elif [[ $ret -eq 2 ]]; then
exit 1
fi
kube::util::gen-doc "${gendocs}" "${KUBE_ROOT}/docs/" '###### Auto generated by spf13/cobra'
kube::util::gen-doc "${genman}" "${KUBE_ROOT}/docs/man/man1"
kube::util::gen-doc "${genbashcomp}" "${KUBE_ROOT}/contrib/completions/bash/"
kube::util::gen-analytics "${KUBE_ROOT}"
# ex: ts=2 sw=2 et filetype=sh

View File

@ -60,10 +60,10 @@ if [[ $ret -eq 2 ]]; then
fi
kube::util::gen-doc "${genman}" "${TMP_DOCROOT}/man/man1/"
kube::util::gen-doc "${gendocs}" "${TMP_DOCROOT}"
kube::util::gen-doc "${gendocs}" "${TMP_DOCROOT}" '###### Auto generated by spf13/cobra'
echo "diffing ${DOCROOT} against freshly generated docs"
ret=0
diff -Naupr -I 'Auto generated by' "${DOCROOT}" "${TMP_DOCROOT}" || ret=$?
diff -Naupr "${DOCROOT}" "${TMP_DOCROOT}" || ret=$?
rm -rf "${_tmp}"
needsanalytics=($(kube::util::gen-analytics "${KUBE_ROOT}" 1))
if [[ ${#needsanalytics[@]} -ne 0 ]]; then