forked from astropy/astropy-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·134 lines (115 loc) · 3.93 KB
/
deploy
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# this conditional assignment means you can do things like:
# GH_REMOTE=myremote ./deploy
# to set these to something other than the default
# branches and remote for pushing to github
: ${GH_PAGESBRANCH=gh-pages}
: ${GH_REMOTE=origin}
# if not interactive, automatically "yes" things but don't show anything
: ${INTERACTIVE=true}
: ${CURRENT_BRANCH_NAME="$(git symbolic-ref --quiet --short HEAD)"}
if [ -z "$CURRENT_BRANCH_NAME" ]; then
echo "Could not determine current branch. Cannot continue with deployment."
exit 1
fi
giveup_message () {
echo "\n"
echo "You're now in an orphaned test deploy branch."
echo "To get back to normal you can run the following:"
echo " git checkout -f $CURRENT_BRANCH_NAME"
echo " git clean -f"
echo " git branch -D $GH_PAGESBRANCH"
}
promptifinteractive () {
# first argument is message, second is non-interactive answer, all others passed to read
if [ "$INTERACTIVE" = true ] ; then
read -p "$1" -r "${@:3}"
else
echo $1 $2
REPLY=$2
fi
}
echo "*****************************************************************"
echo "WARNING! This script will remove the local $GH_PAGESBRANCH branch,"
echo "build the notebook files into HTML, then push to remote gh-pages"
echo "located here: $GH_REMOTE/gh-pages."
echo
echo "Make sure you have no uncommitted changes in your current branch"
echo "as these may be overwritten!"
echo
promptifinteractive "Are you sure you want to do this? [y/N] " y -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# first run the notebooks
OUTPUT=`python prepare_deploy.py run`
if [[ $OUTPUT == *ERROR* ]]
then
echo "Error running notebook files!";
exit;
fi
# then convert the notebooks to HTML
OUTPUT=`python prepare_deploy.py convert`
if [[ $OUTPUT == *ERROR* ]]
then
echo "Error converting notebook files to HTML!";
exit;
fi
# remove the old $GH_PAGESBRANCH branch
OUTPUT=`git branch -D $GH_PAGESBRANCH`
if [[ $OUTPUT == *fatal* ]]
then
echo "Error deleting branch '$GH_PAGESBRANCH'.";
exit;
fi
# Create a new "orphaned" branch -- we don't need history for
# the built products
git checkout --orphan $GH_PAGESBRANCH
# Copy the built files to a tmp location
cp -R html _tmp
# This will delete all of the git-managed files here
git rm -rf .
# Now copy the html back into here
cp -R _tmp/* .
rm -rf _tmp
git add *.html
git add images
git add css
git commit -m "Generated from sources"
promptifinteractive "Would you like to preview the rendered HTML? [y/N] " N -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
echo
open index.html
else
echo
fi
promptifinteractive "Are you sure you want to push to the remote branch '$GH_PAGESBRANCH' on the remote '$GH_REMOTE'? [y/N] " y -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
git ls-remote --exit-code $GH_REMOTE > /dev/null 2> /dev/null
while [[ $? != 0 ]]
do
promptifinteractive "Could not communicate with remote '$GH_REMOTE'. Enter an alternate remote name (or 'quit' to give up):" quit
if [[ $REPLY = "quit" ]]; then
giveup_message
exit
fi
GH_REMOTE=$REPLY
git ls-remote --exit-code $GH_REMOTE > /dev/null 2> /dev/null
done
echo "Pushing to '$GH_PAGESBRANCH' on remote '$GH_REMOTE'"
if [ "$INTERACTIVE" = true ] ; then
git push -f $GH_REMOTE $GH_PAGESBRANCH
else
# we do this with nothing to stdout because otherwise it might reveal secret tokens
git push -f --quiet $GH_REMOTE $GH_PAGESBRANCH >/dev/null 2>&1
echo "Silent push finished."
fi
git checkout -f $CURRENT_BRANCH_NAME
git clean -f
git branch -D $GH_PAGESBRANCH
else
giveup_message
fi
fi