forked from astropy-learn/astropy-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·107 lines (91 loc) · 3.01 KB
/
deploy
File metadata and controls
executable file
·107 lines (91 loc) · 3.01 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
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
#!/bin/bash
GH_PAGESBRANCH=gh-pages
GH_REMOTE=origin
# get current git branch name - should throw an error if in a detached state
current_branch_name="$(git symbolic-ref --short HEAD)"
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"
}
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
read -p "Are you sure you want to do this? [y/N] " -n 1 -r
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"
read -p "Would you like to preview the rendered HTML? [y/N] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
echo
open index.html
else
echo
fi
read -p "Are you sure you want to push to the remote branch '$GH_PAGESBRANCH' on the remote '$GH_REMOTE'? [y/N] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
git ls-remote --exit-code $GH_REMOTE > /dev/null 2> /dev/null
while [[ $? != 0 ]]
do
read -p "Could not communicate with remote '$GH_REMOTE'. Enter an alternate remote name (or 'quit' to give up):" -r
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'"
git push -f $GH_REMOTE $GH_PAGESBRANCH
git checkout -f $current_branch_name
git clean -f
git branch -D $GH_PAGESBRANCH
else
giveup_message
fi
fi