-
Notifications
You must be signed in to change notification settings - Fork 29
/
deploy_doc.sh
executable file
·62 lines (47 loc) · 1.58 KB
/
deploy_doc.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
#!/usr/bin/env bash
set -euo pipefail
DOC_SRC="src_docs"
unset GITHUB_TOKEN
# check that "$DOC_SRC" dir exists
if [ ! -d "$DOC_SRC" ]; then
echo "The '$DOC_SRC' dir doesn't exist, are you in the right directory?"
exit 1
fi
# check that virtual env is activated
if [ -z "${VIRTUAL_ENV:-""}" ]; then
echo "A python virtual env is not activated in this shell." >&2
exit 1
fi
# check that current branch is "master"
cur_branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$cur_branch" != "master" ]; then
printf "WARNING: You are in '%s' branch instead of 'master'! Press ENTER to contunue or CTRL+C to abort." "$cur_branch"
read -r
fi
# check that there are no uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo "There are uncommitted changes, aborting."
exit 1
fi
# build documentation
make doc
# drop changes made automatically by `make doc`
if ! git diff-index --quiet HEAD -- "$DOC_SRC"; then
git stash -- "$DOC_SRC"
git stash drop
fi
# checkout the "github_pages" branch
git checkout github_pages
# reset the "github_pages" branch
git reset --hard upstream/master
# copy generated documention to 'docs' dir
rm -rf docs/*
cp -aT "$DOC_SRC"/build/html docs
# stage changes
git add docs
# commit changes
git commit -n -m "Documentation update"
# push to origin/github_pages (upstream/github_pages)
printf "\n-------------------------------------------\n\n"
printf "Push changes manually:\ngit push -f origin github_pages\nor\ngit push -f upstream github_pages\n\n"
printf "Then switch back to '%s' branch:\ngit checkout %s\n" "$cur_branch" "$cur_branch"