Debian Codegraph @

tools/scripts/push_docs.sh

raw
1 #!/usr/bin/env bash
2 # Copyright 2015 Google Inc. All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Publishes a new version of the Jsonnet website.
17 #
18 # This script does the following:
19 #
20 # 1. Builds an archive containing the Jekyll website
21 # 2. In a temporary directory or the provided WORKING_DIR, clones the
22 # Jsonnet website, and checks out the gh-pages branch
23 # 3. Replaces the contents of the repository with the new version of the site
24 # from the archive
25 # 4. Commits the new version of the site and pushes to the remote repository.
26 #
27 # Usage:
28 # push_docs.sh [WORKING_DIR]
29
30 set -e
31
32 readonly JSONNET_REPO="[email protected].:google/jsonnet.git"
33 readonly JSONNET_REPO_HTTPS="https://github.com/google/jsonnet.git"
34
35 function check {
36 which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1)
37 }
38
39 [ -x ./jsonnet ] || (echo "Please build ./jsonnet first."; exit 1)
40 check git
41 check jekyll
42
43 if [ ! -t 0 ]; then
44 echo "Not attached to a TTY. Can't prompt the user for confirmation. Exiting." >&1
45 exit 1
46 fi
47
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
51 exit 1
52 fi
53
54 working_dir=$1
55 if [ -z "$working_dir" ]; then
56 working_dir=$(mktemp -d "/tmp/jsonnet_gh_pages_XXXX")
57 # Clean it up automatically on exit.
58 trap "rm -rf ${working_dir}" EXIT
59 fi
60
61 git clone \
62 -b gh-pages \
63 --origin origin \
64 --config "remote.origin.pushUrl=$JSONNET_REPO" \
65 "$JSONNET_REPO_HTTPS" \
66 "$working_dir"
67
68 (
69 cd "$working_dir"
70 git checkout gh-pages
71 rm $(git ls-tree --name-only -r HEAD)
72 )
73
74 tools/scripts/update_web_content.sh
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
84
85 (
86 cd "$working_dir"
87 git add .
88 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..."
113 git push -u origin gh-pages
114 )