Skip to content

Commit 8500342

Browse files
enhancements to the push_docs.sh script
Various things that make it easier for me personally to use: - Use an HTTPS pull URL (still the SSH push URL). This is because pulling over HTTPS doesn't need authentication but pushing needs me to tap my security key; cloning over HTTPS halves the number of taps I need. - Don't require libjsonnet.wasm to exist - we can just keep the existing one from the gh-pages branch if there isn't a newly built one to use. - Require running on a TTY and prompt the user for confirmation before the push. Probably not what we want long term but I was running the script a lot to check things and didn't want to actually push then.
1 parent c4c7464 commit 8500342

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

tools/scripts/push_docs.sh

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@
3030
set -e
3131

3232
readonly JSONNET_REPO="[email protected].:google/jsonnet.git"
33+
readonly JSONNET_REPO_HTTPS="https://github.com/google/jsonnet.git"
3334

3435
function check {
3536
which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1)
3637
}
3738

39+
[ -x ./jsonnet ] || (echo "Please build ./jsonnet first."; exit 1)
3840
check git
3941
check jekyll
4042

41-
if [ ! -r 'doc/_config.yml' ]; then
42-
echo 'No doc/_config.yml file found.' >&1
43-
echo 'Are you running this script from the root of the Jsonnet repository?' >&1
43+
if [ ! -t 0 ]; then
44+
echo "Not attached to a TTY. Can't prompt the user for confirmation. Exiting." >&1
4445
exit 1
4546
fi
4647

47-
if [ ! -r 'doc/js/libjsonnet.wasm' ]; then
48-
echo 'Cannot push as doc/js/libjsonnet.wasm has not been built.' >&1
48+
if [ ! -r 'doc/_config.yml' ]; then
49+
echo 'No doc/_config.yml file found.' >&1
50+
echo 'Are you running this script from the root of the Jsonnet repository?' >&1
4951
exit 1
5052
fi
5153

@@ -56,7 +58,12 @@ if [ -z "$working_dir" ]; then
5658
trap "rm -rf ${working_dir}" EXIT
5759
fi
5860

59-
git clone -b gh-pages $JSONNET_REPO "$working_dir"
61+
git clone \
62+
-b gh-pages \
63+
--origin origin \
64+
--config "remote.origin.pushUrl=$JSONNET_REPO" \
65+
"$JSONNET_REPO_HTTPS" \
66+
"$working_dir"
6067

6168
(
6269
cd "$working_dir"
@@ -65,12 +72,43 @@ git clone -b gh-pages $JSONNET_REPO "$working_dir"
6572
)
6673

6774
tools/scripts/update_web_content.sh
68-
cd doc
69-
jekyll build -d "$working_dir"
75+
jekyll build -s doc -d "$working_dir"
76+
77+
if [ ! -r "$working_dir/js/libjsonnet.wasm" ]; then
78+
echo 'We have no js/libjsonnet.wasm; restoring the existing one from git' >&1
79+
(
80+
cd "$working_dir"
81+
git checkout -- js/libjsonnet.wasm
82+
)
83+
fi
7084

7185
(
7286
cd "$working_dir"
7387
git add .
7488
git commit -am "Update docs."
89+
90+
if [ -t 0 ]; then
91+
# We're on a TTY. Prompt the user for input.
92+
while true; do
93+
read -p "Push new gh-pages commit? Y/n " yn
94+
case "$yn" in
95+
Y* )
96+
break
97+
;;
98+
[nN]* )
99+
echo "ok; aborting."
100+
exit
101+
;;
102+
* )
103+
echo "please enter 'Y' or 'n'"
104+
;;
105+
esac
106+
done
107+
else
108+
# Not on a TTY. Exit.
109+
exit 1
110+
fi
111+
112+
echo "Pushing gh-pages..."
75113
git push -u origin gh-pages
76114
)

0 commit comments

Comments
 (0)