-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdeploy.sh
70 lines (56 loc) · 1.66 KB
/
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
#!/usr/bin/env bash
# A script to build griffin site (based on jekyll)
# specify source and site branches
SOURCE="master"
SITE="asf-site"
# Make sure on the SOURCE branch
git checkout $SOURCE > /dev/null 2>&1
# Get the latest commit SHA in SOURCE branch
last_SHA=( $(git log -n 1 --pretty=format:"%H") )
# use last commit sha as temp folder name
tmp_dir="temp_$last_SHA"
# Build the Jekyll site to our temporary folder
jekyll build -d ~/$tmp_dir > /dev/null 2>&1
if [ $? = 0 ]; then
echo "Jekyll build successful"
else
echo "Jekyll build failed"
exit 1
fi
# Switch to the SITE branch
git checkout $SITE > /dev/null 2>&1
if [ $? = 1 ]; then
# Branch does not exist. Create an orphan branch.
git checkout -b $SITE > /dev/null 2>&1
git add --all .
git commit -m "Initial commit" > /dev/null 2>&1
echo "$SITE branch does not exist, create new branch $SITE"
fi
# Remove the current contents of the SITE branch and
# replace them with the contents of the temp folder
current_dir=${PWD}
rm -r $current_dir/*
git rm -r --cached * > /dev/null 2>&1
cp -r ~/$tmp_dir/* $current_dir
# Commit the changes to the SITE branch
message="Updated $SITE site from $SOURCE ($last_SHA)"
git add --all .
git commit -m "$message" > /dev/null 2>&1
# Delete the temporary folder
rm -r ~/$tmp_dir
# Push latest SITE to server
git push -u origin $SITE -f > /dev/null 2>&1
if [ $? = 0 ]; then
echo "Push $SITE successful"
else
echo "Push $SITE failed"
fi
# Switch back to SOURCE branch
git checkout $SOURCE > /dev/null 2>&1
# Push the SOURCE to the server
git push -u origin $SOURCE > /dev/null 2>&1
if [ $? = 0 ]; then
echo "Push $SOURCE successful"
else
echo "Push $SOURCE failed"
fi