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