-
Notifications
You must be signed in to change notification settings - Fork 12
/
publish_docs.sh
executable file
·42 lines (32 loc) · 1.04 KB
/
publish_docs.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
#!/bin/bash
# Any individual commands that fail will cause the script to exit
set -e
BRANCH=`git branch | sed -n -e 's/^\* \(.*\)/\1/p'`
make docs
# Initialize a blank branch or change to the existing one
# Exit if all fail as a precautionary measure to not trash
# the current branch
git fetch origin
git checkout --orphan gh-pages || git checkout -f gh-pages || exit 1
# Go back to the original branch. Set this as a trap to happen if any
# errors occur
function clean_up() {
git checkout -f $BRANCH
}
trap clean_up EXIT
# Start docs from scratch
git ls-files | xargs rm -f
git add -u
# The .nojekyll file prevents github from parsing docs as jekyll format
touch .nojekyll
# Move doc files into root dir, add them, and push them. Exlude hidden
# files and the dot folder
DOC_FILES=`cd docs/_build/html && find . -not -path '*/\.*' -not -path .`
cp -r docs/_build/html/* .
git add -f .nojekyll $DOC_FILES
git commit -m "Published docs" --allow-empty
git push origin gh-pages --force
# Remove the trap and exit normally
trap - EXIT
clean_up
exit 0