Skip to content

Commit b17c1e6

Browse files
ahmetbchenopis
authored andcommitted
update-imported-docs.sh script improvements (kubernetes#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 <[email protected]>
1 parent 8bec7d7 commit b17c1e6

File tree

1 file changed

+57
-59
lines changed

1 file changed

+57
-59
lines changed

update-imported-docs.sh

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
set -o errexit
3+
24

35
# Uncomment this to see the commands as they are run
46
# set -x
@@ -36,88 +38,87 @@ function process_api_ref_docs {
3638
APIREFPATH=docs/api-reference
3739
KUBECTLPATH=docs/user-guide/kubectl
3840
TMPDIR=/tmp/update_docs
39-
TMPAPIREFDIR=${TMPDIR}'/api_ref'
40-
TMPKUBECTLDIR=${TMPDIR}'/kubectl'
41-
42-
rm -rf ${TMPDIR}
43-
mkdir ${TMPDIR}
44-
mkdir ${TMPAPIREFDIR}
45-
mkdir ${TMPKUBECTLDIR}
46-
47-
APIREFSRCDIR=${APIREFPATH}'/v'${OLDVERSION}
48-
APIREFDESDIR=${TMPAPIREFDIR}'/v'${OLDVERSION}
49-
mv ${APIREFSRCDIR} ${APIREFDESDIR}
50-
KUBECTLSRCDIR=${KUBECTLPATH}'/v'${OLDVERSION}
51-
KUBECTLDESDIR=${TMPKUBECTLDIR}'/v'${OLDVERSION}
52-
mv ${KUBECTLSRCDIR} ${KUBECTLDESDIR}
53-
54-
git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git k8s
55-
cd k8s
56-
git remote add upstream https://github.com/kubernetes/kubernetes.git
57-
git fetch upstream
58-
hack/generate-docs.sh
59-
cd ..
60-
61-
rm -rf _includes/v$VERSION
62-
mkdir _includes/v$VERSION
41+
TMPAPIREFDIR="${TMPDIR}/api_ref"
42+
TMPKUBECTLDIR="${TMPDIR}/kubectl"
43+
44+
rm -rf -- "${TMPDIR}"
45+
mkdir -p -- "${TMPAPIREFDIR}" "${TMPKUBECTLDIR}"
46+
47+
APIREFSRCDIR="${APIREFPATH}/v${OLDVERSION}"
48+
APIREFDESDIR="${TMPAPIREFDIR}/v${OLDVERSION}"
49+
mv -- "${APIREFSRCDIR}" "${APIREFDESDIR}"
50+
KUBECTLSRCDIR="${KUBECTLPATH}/v${OLDVERSION}"
51+
KUBECTLDESDIR="${TMPKUBECTLDIR}/v${OLDVERSION}"
52+
mv -- "${KUBECTLSRCDIR}" "${KUBECTLDESDIR}"
53+
54+
K8SREPO=k8s
55+
(
56+
git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git "${K8SREPO}"
57+
cd "${K8SREPO}"
58+
hack/generate-docs.sh
59+
)
60+
61+
62+
rm -rf "_includes/v$VERSION"
63+
mkdir "_includes/v$VERSION"
6364

6465
# batch fetches
6566
while read line || [[ -n ${line} ]]; do
6667
IFS=': ' read -a myarray <<< "${line}"
6768
if [ "${myarray[1]}" = "path" ]; then
6869
TARGET="${myarray[2]}"
6970
CLEARPATH="${TARGET}"
70-
K8SSOURCE='k8s/'${TARGET}
71+
K8SSOURCE="${K8SREPO}/${TARGET}"
7172
DESTINATION=${TARGET%/*}
72-
rm -rf "${CLEARPATH}"
73-
yes | cp -rf "${K8SSOURCE}" "${DESTINATION}"
73+
rm -rf -- "${CLEARPATH}"
74+
yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}"
7475
fi
7576
if [ "${myarray[1]}" = "changedpath" ]; then
7677
SRC="${myarray[2]}"
7778
DESTINATION="${myarray[3]}"
78-
echo "mv -f ${SRC} ${DESTINATION}"
79-
yes | cp -rf "${SRC}" "${DESTINATION}"
79+
echo "cp -rf -- ${SRC} ${DESTINATION}"
80+
yes | cp -rf -- "${SRC}" "${DESTINATION}"
8081
fi
8182
if [ "${myarray[1]}" = "copypath" ]; then
8283
K8SSOURCE="${myarray[2]}"
8384
DESTINATION="${myarray[3]}"
84-
echo "yes | cp -rf ${K8SSOURCE} ${DESTINATION}"
85-
yes | cp -rf "${K8SSOURCE}" "${DESTINATION}"
85+
echo "yes | cp -rf -- ${K8SSOURCE} ${DESTINATION}"
86+
yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}"
8687
fi
8788
done <_data/overrides.yml
8889

8990
# refdoc munging
90-
pushd .
91-
cd _includes/v$VERSION
91+
(
92+
cd _includes/v$VERSION
9293
# These are included in other files, so strip the DOCTYPE
9394
find . -name '*.html' -type f -exec sed -i -e "s/<!DOCTYPE html>//g" {} \;
9495

9596
# Format html
9697
find . -name '*.html' -type f -exec sed -i -e '/<style>/,/<\/style>/d' {} \;
9798
find . -name '*.html' -type f -exec sed -i -e "s/http:\/\/kubernetes.io\/v$VERSION//g" {} \;
98-
popd
99+
)
99100

100-
pushd .
101-
cd docs/api-reference
101+
(
102+
cd docs/api-reference
102103
process_api_ref_docs
103104

104105
# Fix for bug in 1.3 release
105106
find . -name '*.md' -type f -exec sed -i -e "s/vv1.3.0-beta.0/v1.3/g" {} \;
106-
popd
107+
)
107108

108-
pushd .
109-
cd docs/federation/api-reference
109+
(
110+
cd docs/federation/api-reference
110111
process_api_ref_docs
111112

112113
# Rename README.md to index.md
113114
mv README.md index.md
114115
# Update the links from federation/docs/api-reference to
115116
# docs/federation/api-reference
116117
find . -name '*.*' -type f -exec sed -i -e "s/federation\/docs\/api-reference/docs\/federation\/api-reference/g" {} \;
117-
popd
118+
)
118119

119-
pushd .
120-
cd docs/user-guide/kubectl
120+
(
121+
cd docs/user-guide/kubectl
121122
# Strip the munge comments
122123
find . -name '*.md' -type f -exec sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' {} \;
123124
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
127128
find . -name 'kubectl*.md' -type f -exec sed -i -e '/### SEE ALSO/d' {} \;
128129
find . -name 'kubectl*.md' -type f -exec sed -i -e '/\* \[kubectl/d' {} \;
129130

130-
# Add the expected headers to md files
131+
# Add the expected headers to md files
131132
find . -name '*.md' -type f -exec sed -i -e '1 i\
132133
---' {} \;
133134
find . -name '*.md' -type f -exec sed -i -e '1 i\
134135
---' {} \;
135-
popd
136+
)
136137

137138

138139
BINARIES="federation-apiserver.md federation-controller-manager.md kube-apiserver.md kube-controller-manager.md kube-proxy.md kube-scheduler.md kubelet.md"
139140

140-
pushd .
141-
cd docs/admin
141+
(
142+
cd docs/admin
142143
for bin in $BINARIES; do
143-
sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' $bin
144-
sed -i -e '/<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->/,/<!-- END MUNGE: UNVERSIONED_WARNING -->/d' $bin
145-
sed -i -e '1 i\
146-
---' $bin
147-
sed -i -e '1 i\
148-
---' $bin
144+
sed -i -e '/<!-- BEGIN MUNGE: IS_VERSIONED -->/,/<!-- END MUNGE: IS_VERSIONED -->/d' "$bin"
145+
sed -i -e '/<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->/,/<!-- END MUNGE: UNVERSIONED_WARNINgG -->/d' "$bin"
146+
sed -i -e '1 i\
147+
---' "$bin"
148+
sed -i -e '1 i\
149+
---' "$bin"
149150
done
150-
popd
151-
152-
rm -rf k8s
153-
154-
mv ${APIREFDESDIR} ${APIREFSRCDIR}
155-
mv ${KUBECTLDESDIR} ${KUBECTLSRCDIR}
156-
rm -rf ${TMPDIR}
151+
)
152+
mv -- "${APIREFDESDIR}" "${APIREFSRCDIR}"
153+
mv -- "${KUBECTLDESDIR}" "${KUBECTLSRCDIR}"
154+
rm -rf -- "${TMPDIR}" "${K8SREPO}"
157155

158156
echo "Docs imported! Run 'git add .' 'git commit -m <comment>' and 'git push' to upload them"

0 commit comments

Comments
 (0)