This repository has been archived by the owner on Oct 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc_build.sh
125 lines (123 loc) · 2.82 KB
/
doc_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
trap ctrl_c INT
ctrl_c ()
{
if [ -d "$tempclone" ]; then
rm -rf "$tempclone"
fi
if [ "$pushdired" = true ]; then
popd > /dev/null
fi
}
BUILD=true
PUSH=false
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--no-build)
BUILD=false
;;
--push)
PUSH=true
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
if [ $BUILD = false ] && [ $PUSH = false ]; then
echo "Error: Not building and not pushing"
echo "At least one of these actions must be performed"
ctrl_c
exit 1
fi
tempclone=$(mktemp -d "doc_build_clone.XXXXXXXX")
echo $tempclone
if [ $PUSH = false ]; then
echo "Only verification will be performed."
fi
if [ $BUILD = true ]; then
echo "Building documentation"
cd docs
sphinx-build -b html -d build/doctrees source build/html
makestatus=$?
cd ..
else
echo "Using previously built documentation"
makestatus=0
fi
if [ $makestatus -ne 0 ]; then
echo -e "\e[0;31mDocumentation building failed\e[0m"
if [ ! -d "docs/build/html" ]; then
echo -e "\e[0;31mDocumentation is not built\e[0m"
ctrl_c
exit 1
else
echo -e "\e[0;31mUsing previously built documentation\e[0m"
fi
else
echo -e "\e[0;32mDocumentation successfully built\e[0m"
fi
SHA=$(git rev-parse --short --verify HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ $PUSH = false ]; then
echo "Exiting after doc verification"
ctrl_c
exit 0
fi
cd docs/build/html
builtdocs=$PWD
cd ../../..
pushd "$tempclone" > /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[0;31mFailed to use temp directory\e[0m"
ctrl_c
exit 1
fi
pushdired=true
# When running locally, use https as it is easier to configure
url=https://github.com/rlee287/pyautoupdate
git clone --depth 1 -b gh-pages $url
if [ $? -ne 0 ]; then
echo -e "\e[0;31mFailed to clone current gh-pages repo\e[0m"
ctrl_c
exit 1
fi
cd pyautoupdate
git ls-files | xargs rm
shopt -u | grep -q dotglob && changed=true && shopt -s dotglob
cp --no-preserve=mode --no-preserve=ownership -r $builtdocs/* .
[ $changed ] && shopt -u dotglob; unset changed
# Keep some of the existing indicator files
git checkout -- .nojekyll
git checkout -- .gitignore
# This step is necessary on Windows Cygwin
# Or other systems that do not handle executable bits properly
chmod -x ./*
chmod -x ./**/*
git config --local core.fileMode true
git diff --stat
echo "Checking for changed documentation"
git diff --quiet
hasdiff=$?
if [ $hasdiff -eq 0 ]; then
echo "Documentation has not changed"
echo "No need to update"
ctrl_c
exit 0
fi
cat << EOF > commitmessage
Sphinx rebuild
This corresponds to commit $SHA on branch $BRANCH
EOF
echo "Committing updated documentation"
git add --all
git reset HEAD commitmessage
git diff --staged --stat
git commit -F commitmessage
rm commitmessage
echo "Pushing to gh-pages"
git push
ctrl_c