mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Add ga-beacon analytics to gendocs scripts
hack/run-gendocs.sh puts ga-beacon analytics link into all md files, hack/verify-gendocs.sh verifies presence of link.
This commit is contained in:
@@ -31,3 +31,6 @@ by executing it from the git checkout. Since Jenkins is an entity
|
||||
outside this repository, it's tricky to keep documentation for it up
|
||||
to date quickly. However, the scripts themselves attempt to provide
|
||||
color for the configuration(s) that each script runs in.
|
||||
|
||||
|
||||
[]()
|
||||
|
@@ -136,14 +136,21 @@ kube::util::gen-doc() {
|
||||
# create the list of generated files
|
||||
ls "${tmpdir}" | LC_ALL=C sort > "${tmpdir}/.files_generated"
|
||||
|
||||
# remove all old generated file from the destination
|
||||
while read file; do
|
||||
# Add analytics link to generated .md files
|
||||
if [[ "${file}" == *.md ]]; then
|
||||
local link path
|
||||
path=$(basename "$dest")/${file}
|
||||
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
|
||||
local original generated
|
||||
original=$(grep -v "^${skipprefix}" "${dest}/${file}") || :
|
||||
generated=$(grep -v "^${skipprefix}" "${tmpdir}/${file}") || :
|
||||
if [[ "${original}" == "${generated}" ]]; then
|
||||
# overwrite generated with original.
|
||||
# actual contents same, overwrite generated with original.
|
||||
mv "${dest}/${file}" "${tmpdir}/${file}"
|
||||
fi
|
||||
else
|
||||
@@ -157,4 +164,44 @@ kube::util::gen-doc() {
|
||||
rm -rf "${tmpdir}"
|
||||
}
|
||||
|
||||
# Takes a path $1 to traverse for md files to append the ga-beacon tracking
|
||||
# link to, if needed. If $2 is set, just print files that are missing
|
||||
# the link.
|
||||
kube::util::gen-analytics() {
|
||||
local path="$1"
|
||||
local dryrun="${2:-}"
|
||||
local mdfiles dir link
|
||||
# find has some strange inconsistencies between darwin/linux. The
|
||||
# path to search must end in '/' for linux, but darwin will put an extra
|
||||
# slash in results if there is a trailing '/'.
|
||||
if [[ $( uname ) == 'Linux' ]]; then
|
||||
dir="${path}/"
|
||||
else
|
||||
dir="${path}"
|
||||
fi
|
||||
# We don't touch files in Godeps|third_party, and the kubectl
|
||||
# docs are autogenerated by gendocs.
|
||||
mdfiles=($( find "${dir}" -name "*.md" -type f \
|
||||
-not -path "${path}/Godeps/*" \
|
||||
-not -path "${path}/third_party/*" \
|
||||
-not -path "${path}/_output/*" \
|
||||
-not -path "${path}/docs/kubectl*" ))
|
||||
for f in "${mdfiles[@]}"; do
|
||||
link=$(kube::util::analytics-link "${f#${path}/}")
|
||||
if grep -q -F -x "${link}" "${f}"; then
|
||||
continue
|
||||
elif [[ -z "${dryrun}" ]]; then
|
||||
echo -e "\n\n${link}" >> "${f}"
|
||||
else
|
||||
echo "$f"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Prints analytics link to append to a file at path $1.
|
||||
kube::util::analytics-link() {
|
||||
local path="$1"
|
||||
echo "[]()"
|
||||
}
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
||||
|
@@ -42,5 +42,6 @@ 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
|
||||
|
@@ -39,20 +39,25 @@ if [[ ! -x "$gendocs" || ! -x "$genman" || ! -x "$genbashcomp" ]]; then
|
||||
fi
|
||||
|
||||
DOCROOT="${KUBE_ROOT}/docs/"
|
||||
TMP_DOCROOT="${KUBE_ROOT}/docs_tmp/"
|
||||
TMP_DOCROOT="${KUBE_ROOT}/_tmp/docs/"
|
||||
_tmp="${KUBE_ROOT}/_tmp"
|
||||
|
||||
mkdir -p "${_tmp}"
|
||||
cp -a "${DOCROOT}" "${TMP_DOCROOT}"
|
||||
|
||||
kube::util::gen-doc "${genman}" "${TMP_DOCROOT}/man/man1/"
|
||||
kube::util::gen-doc "${gendocs}" "${TMP_DOCROOT}"
|
||||
|
||||
echo "diffing ${DOCROOT} against freshly generated docs"
|
||||
set +e
|
||||
diff -Naupr -I 'Auto generated by' "${DOCROOT}" "${TMP_DOCROOT}"
|
||||
ret=$?
|
||||
set -e
|
||||
rm -rf "${TMP_DOCROOT}"
|
||||
if [ $ret -eq 0 ]
|
||||
ret=0
|
||||
diff -Naupr -I 'Auto generated by' "${DOCROOT}" "${TMP_DOCROOT}" || ret=$?
|
||||
rm -rf "${_tmp}"
|
||||
needsanalytics=($(kube::util::gen-analytics "${KUBE_ROOT}" 1))
|
||||
if [[ ${#needsanalytics[@]} -ne 0 ]]; then
|
||||
echo -e "Some md files are missing ga-beacon analytics link:"
|
||||
printf '%s\n' "${needsanalytics[@]}"
|
||||
ret=1
|
||||
fi
|
||||
if [[ $ret -eq 0 ]]
|
||||
then
|
||||
echo "${DOCROOT} up to date."
|
||||
else
|
||||
@@ -64,10 +69,8 @@ COMPROOT="${KUBE_ROOT}/contrib/completions"
|
||||
TMP_COMPROOT="${KUBE_ROOT}/contrib/completions_tmp"
|
||||
cp -a "${COMPROOT}" "${TMP_COMPROOT}"
|
||||
kube::util::gen-doc "${genbashcomp}" "${TMP_COMPROOT}/bash/"
|
||||
set +e
|
||||
diff -Naupr "${COMPROOT}" "${TMP_COMPROOT}"
|
||||
ret=$?
|
||||
set -e
|
||||
ret=0
|
||||
diff -Naupr "${COMPROOT}" "${TMP_COMPROOT}" || ret=$?
|
||||
rm -rf ${TMP_COMPROOT}
|
||||
if [ $ret -eq 0 ]
|
||||
then
|
||||
|
Reference in New Issue
Block a user