update-imported-docs.sh script improvements (#3446)

- avoiding cloning the full history of k8s repo, there doesn't seem to be any
  difference (--depth=1 gives the same result and fetched branches are not
  used in this script)
- quoting around variables and add '--' to some commands to separate positional
  arguments
- using subshells instead of pushd/popd stuff, easier to read IMO
- added 'set -o errexit', couldn't add 'set -o pipefail'. For some reason when
  I enable pipefail, it produces a vastly different output but I don't see any
  errors in the output.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2017-04-19 14:35:10 -07:00 committed by Andrew Chen
parent 8bec7d7c8a
commit b17c1e6b82
1 changed files with 53 additions and 55 deletions

View File

@ -1,4 +1,6 @@
#!/bin/bash
set -o errexit
# Uncomment this to see the commands as they are run
# set -x
@ -36,30 +38,29 @@ function process_api_ref_docs {
APIREFPATH=docs/api-reference
KUBECTLPATH=docs/user-guide/kubectl
TMPDIR=/tmp/update_docs
TMPAPIREFDIR=${TMPDIR}'/api_ref'
TMPKUBECTLDIR=${TMPDIR}'/kubectl'
TMPAPIREFDIR="${TMPDIR}/api_ref"
TMPKUBECTLDIR="${TMPDIR}/kubectl"
rm -rf ${TMPDIR}
mkdir ${TMPDIR}
mkdir ${TMPAPIREFDIR}
mkdir ${TMPKUBECTLDIR}
rm -rf -- "${TMPDIR}"
mkdir -p -- "${TMPAPIREFDIR}" "${TMPKUBECTLDIR}"
APIREFSRCDIR=${APIREFPATH}'/v'${OLDVERSION}
APIREFDESDIR=${TMPAPIREFDIR}'/v'${OLDVERSION}
mv ${APIREFSRCDIR} ${APIREFDESDIR}
KUBECTLSRCDIR=${KUBECTLPATH}'/v'${OLDVERSION}
KUBECTLDESDIR=${TMPKUBECTLDIR}'/v'${OLDVERSION}
mv ${KUBECTLSRCDIR} ${KUBECTLDESDIR}
APIREFSRCDIR="${APIREFPATH}/v${OLDVERSION}"
APIREFDESDIR="${TMPAPIREFDIR}/v${OLDVERSION}"
mv -- "${APIREFSRCDIR}" "${APIREFDESDIR}"
KUBECTLSRCDIR="${KUBECTLPATH}/v${OLDVERSION}"
KUBECTLDESDIR="${TMPKUBECTLDIR}/v${OLDVERSION}"
mv -- "${KUBECTLSRCDIR}" "${KUBECTLDESDIR}"
git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git k8s
cd k8s
git remote add upstream https://github.com/kubernetes/kubernetes.git
git fetch upstream
hack/generate-docs.sh
cd ..
K8SREPO=k8s
(
git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git "${K8SREPO}"
cd "${K8SREPO}"
hack/generate-docs.sh
)
rm -rf _includes/v$VERSION
mkdir _includes/v$VERSION
rm -rf "_includes/v$VERSION"
mkdir "_includes/v$VERSION"
# batch fetches
while read line || [[ -n ${line} ]]; do
@ -67,46 +68,46 @@ while read line || [[ -n ${line} ]]; do
if [ "${myarray[1]}" = "path" ]; then
TARGET="${myarray[2]}"
CLEARPATH="${TARGET}"
K8SSOURCE='k8s/'${TARGET}
K8SSOURCE="${K8SREPO}/${TARGET}"
DESTINATION=${TARGET%/*}
rm -rf "${CLEARPATH}"
yes | cp -rf "${K8SSOURCE}" "${DESTINATION}"
rm -rf -- "${CLEARPATH}"
yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}"
fi
if [ "${myarray[1]}" = "changedpath" ]; then
SRC="${myarray[2]}"
DESTINATION="${myarray[3]}"
echo "mv -f ${SRC} ${DESTINATION}"
yes | cp -rf "${SRC}" "${DESTINATION}"
echo "cp -rf -- ${SRC} ${DESTINATION}"
yes | cp -rf -- "${SRC}" "${DESTINATION}"
fi
if [ "${myarray[1]}" = "copypath" ]; then
K8SSOURCE="${myarray[2]}"
DESTINATION="${myarray[3]}"
echo "yes | cp -rf ${K8SSOURCE} ${DESTINATION}"
yes | cp -rf "${K8SSOURCE}" "${DESTINATION}"
echo "yes | cp -rf -- ${K8SSOURCE} ${DESTINATION}"
yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}"
fi
done <_data/overrides.yml
# refdoc munging
pushd .
cd _includes/v$VERSION
(
cd _includes/v$VERSION
# These are included in other files, so strip the DOCTYPE
find . -name '*.html' -type f -exec sed -i -e "s/<!DOCTYPE html>//g" {} \;
# Format html
find . -name '*.html' -type f -exec sed -i -e '/<style>/,/<\/style>/d' {} \;
find . -name '*.html' -type f -exec sed -i -e "s/http:\/\/kubernetes.io\/v$VERSION//g" {} \;
popd
)
pushd .
cd docs/api-reference
(
cd docs/api-reference
process_api_ref_docs
# Fix for bug in 1.3 release
find . -name '*.md' -type f -exec sed -i -e "s/vv1.3.0-beta.0/v1.3/g" {} \;
popd
)
pushd .
cd docs/federation/api-reference
(
cd docs/federation/api-reference
process_api_ref_docs
# Rename README.md to index.md
@ -114,10 +115,10 @@ cd docs/federation/api-reference
# Update the links from federation/docs/api-reference to
# docs/federation/api-reference
find . -name '*.*' -type f -exec sed -i -e "s/federation\/docs\/api-reference/docs\/federation\/api-reference/g" {} \;
popd
)
pushd .
cd docs/user-guide/kubectl
(
cd docs/user-guide/kubectl
# Strip the munge comments
find . -name '*.md' -type f -exec sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' {} \;
find . -name '*.md' -type f -exec sed -i -e '/<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->/,/<!-- END MUNGE: UNVERSIONED_WARNING -->/d' {} \;
@ -127,32 +128,29 @@ cd docs/user-guide/kubectl
find . -name 'kubectl*.md' -type f -exec sed -i -e '/### SEE ALSO/d' {} \;
find . -name 'kubectl*.md' -type f -exec sed -i -e '/\* \[kubectl/d' {} \;
# Add the expected headers to md files
# Add the expected headers to md files
find . -name '*.md' -type f -exec sed -i -e '1 i\
---' {} \;
find . -name '*.md' -type f -exec sed -i -e '1 i\
---' {} \;
popd
)
BINARIES="federation-apiserver.md federation-controller-manager.md kube-apiserver.md kube-controller-manager.md kube-proxy.md kube-scheduler.md kubelet.md"
pushd .
cd docs/admin
(
cd docs/admin
for bin in $BINARIES; do
sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' $bin
sed -i -e '/<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->/,/<!-- END MUNGE: UNVERSIONED_WARNING -->/d' $bin
sed -i -e '1 i\
---' $bin
sed -i -e '1 i\
---' $bin
sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' "$bin"
sed -i -e '/<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->/,/<!-- END MUNGE: UNVERSIONED_WARNINgG -->/d' "$bin"
sed -i -e '1 i\
---' "$bin"
sed -i -e '1 i\
---' "$bin"
done
popd
rm -rf k8s
mv ${APIREFDESDIR} ${APIREFSRCDIR}
mv ${KUBECTLDESDIR} ${KUBECTLSRCDIR}
rm -rf ${TMPDIR}
)
mv -- "${APIREFDESDIR}" "${APIREFSRCDIR}"
mv -- "${KUBECTLDESDIR}" "${KUBECTLSRCDIR}"
rm -rf -- "${TMPDIR}" "${K8SREPO}"
echo "Docs imported! Run 'git add .' 'git commit -m <comment>' and 'git push' to upload them"