-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_push_doc.sh
More file actions
executable file
·81 lines (66 loc) · 2.41 KB
/
Copy pathbuild_push_doc.sh
File metadata and controls
executable file
·81 lines (66 loc) · 2.41 KB
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
#!/bin/bash
set -e
# this is a hack, but we have to make sure we're only ever running this from
# the top level of the package and not in the subdirectory...
if [[ ! -f gh_doc_automation/__init__.py ]]; then
echo "This must be run from the gh_doc_automation project directory"
exit 3
fi
# get the running branch
branch=$(git symbolic-ref --short HEAD)
# cd into docs, make them
cd doc
make clean html EXAMPLES_PATTERN=ex_*
cd ..
# move the docs to the top-level directory, stash for checkout
mv doc/_build/html ./
# html/ will stay there actually...
git stash
# checkout gh-pages, remove everything but .git, pop the stash
# switch into the gh-pages branch
git checkout gh-pages
git pull origin gh-pages
# Make sure to set the credentials!
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
git config --global user.name "$GH_NAME" > /dev/null 2>&1
# remove all files that are not in the .git dir
find . -not -name ".git/*" -type f -maxdepth 1 -delete
# Remove the remaining directories. Some of these are artifacts of the LAST
# gh-pages build, and others are remnants of the package itself
declare -a leftover=(".cache/"
".idea/"
"build/"
"build_tools/"
"doc/"
"examples/"
"gh_doc_automation/"
"gh_doc_automation.egg-info/"
"_downloads/"
"_images/"
"_modules/"
"_sources/"
"_static/"
"auto_examples/"
"includes"
"modules/")
# check for each left over file/dir and remove it
for left in "${leftover[@]}"
do
rm -r "$left" || echo "$left does not exist; will not remove"
done
# we need this empty file for git not to try to build a jekyll project
touch .nojekyll
mv html/* ./
rm -r html/
# Add everything, get ready for commit. But only do it if we're on master
if [[ "$CIRCLE_BRANCH" =~ ^master$|^[0-9]+\.[0-9]+\.X$ ]]; then
git add --all
git commit -m "[ci skip] publishing updated documentation..."
# We have to re-add the origin with the GH_TOKEN credentials
git remote rm origin
git remote add origin https://"$GH_NAME":"$GH_TOKEN"@github.com/"$GH_NAME"/gh_automation.git
# NOW we should be able to push it
git push origin gh-pages
else
echo "Not on master, so won't push doc"
fi