-
Notifications
You must be signed in to change notification settings - Fork 126
/
ghpages_deploy.sh
executable file
·82 lines (65 loc) · 1.99 KB
/
ghpages_deploy.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
#
# Publish the Sphinx generated documentation to Gihub Pages
#
# Environment Variables:
# $DOCURL - Custom URL where the documentation would be published.
source logging.sh
while getopts e:i:n:t:r:o: option
do
case "${option}"
in
e) EMAIL=${OPTARG};;
i) UNIQUEID=${OPTARG};;
n) USERNAME=${OPTARG};;
t) OAUTH_TOKEN=${OPTARG};;
r) export REPONAME=${OPTARG};;
o) export OWNER=${OPTARG};;
esac
done
BASE=$(pwd)
LOGFILE=${BASE}/temp/${EMAIL}/ghpages_deploy_${UNIQUEID}.txt
# Setting environment variables
ENVVARS="$(python ${BASE}/modules/scripts/config/__main__.py --source=${BASE}/temp/${EMAIL}/${UNIQUEID}.yaydoc.yml)"
eval ${ENVVARS}
git config --global user.name "Yaydoc Bot"
git config --global user.email "[email protected]"
GIT_HTTPS_URL=https://${USERNAME}:${OAUTH_TOKEN}@github.com/${OWNER}/${REPONAME}.git
cd temp/${EMAIL}
git clone ${GIT_HTTPS_URL} ${UNIQUEID}_pages >>${LOGFILE} 2>>${LOGFILE}
if [ ${?} -ne 0 ]; then
print_danger "Failed to clone gh-pages.\n"
clean
exit 3
fi
print_log "Cloned successfully! \n"
cd ${UNIQUEID}_pages
# Create gh-pages branch if it doesn't exist
git fetch
if ! git checkout gh-pages ; then
print_danger "gh-pages branch doesn't exist. Creating....\n"
git checkout --orphan gh-pages
print_log "gh-pages branch created!\n"
fi
# Overwrite files in the branch
print_log "Overwriting previous content with new changes!\n"
shopt -s extglob
rm -rf ./!(.git)
cp -a ../${UNIQUEID}_preview/. ./
print_log "Overwrite successful \n"
# Enable publishing documentation to custom URL
if [ -z "$DOCURL" ]; then
print_danger "DOCURL not set. Using default github pages URL"
else
print_log "DOCURL set."
echo ${DOCURL} > CNAME
fi
# Publish documentation
print_log "Publishing documentation....\n"
git add -f .
git commit -m "[Auto] Update Built Docs ($(date +%Y-%m-%d.%H:%M:%S))" >>${LOGFILE} 2>>${LOGFILE}
git push origin gh-pages >/dev/null 2>&1
print_log "Documentation published successfully!\n"
cd ..
# Cleanup
rm -rf ${UNIQUEID}_pages