/
update-gh-pages.sh
executable file
·82 lines (75 loc) · 1.66 KB
/
update-gh-pages.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
#!/bin/bash -x
#
# Usage:
#
# $ ./scripts/update-gh-pages.sh v0.6.0 origin
#
tag=${1:-master}
remote=${2:-origin}
ori_branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
tmpdir=$(mktemp -d)
cp -r doc/_build/html/ $tmpdir
git ls-files --others | tar cf $tmpdir/untracked.tar -T -
cleanup() {
git checkout $ori_branch
tar xf $tmpdir/untracked.tar
rm -r $tmpdir
}
trap cleanup INT TERM EXIT
if [[ -d .gh-pages-skeleton ]]; then
cp -r .gh-pages-skeleton $tmpdir
fi
git fetch $remote
git checkout gh-pages
if [[ $? -ne 0 ]]; then
git checkout --orphan gh-pages
if [[ $? -ne 0 ]]; then
>&2 echo "Failed to switch to 'gh-pages' branch."
cleanup
exit 1
fi
preexisting=0
else
preexisting=1
git pull
fi
if [[ $preexisting == 1 ]]; then
while [[ "$(git log -1 --pretty=%B)" == Volatile* ]]; do
# overwrite previous docs
git reset --hard HEAD~1
done
else
git reset --hard
fi
git clean -xfd
if [[ $preexisting == 1 ]]; then
mv v*/ $tmpdir
git rm -rf * > /dev/null
fi
cp -r $tmpdir/html/ $tag
if [[ $preexisting == 1 ]]; then
mv $tmpdir/v*/ .
fi
if [[ -d $tmpdir/.gh-pages-skeleton ]]; then
cp -r $tmpdir/.gh-pages-skeleton/. .
fi
if [[ "$tag" == v* ]]; then
if [[ -L latest ]]; then
rm latest
fi
ln -s $tag latest
commit_msg="Release docs for $tag"
else
if [[ $preexisting == 1 ]]; then
commit_msg="Volatile ($tag) docs"
else
commit_msg="Initial commit"
fi
fi
git add -f . >/dev/null
git commit -m "$commit_msg"
if [[ $preexisting == 1 ]]; then
git push -f $remote gh-pages
else
git push --set-upstream $remote gh-pages
fi