-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·62 lines (49 loc) · 1.45 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
#!/usr/bin/env bash
set -e
BRANCH="gh-pages"
FOLDER="_site"
BUILD_SCRIPT="bin/jekyll build"
CNAME="josephchoe.com"
if [ -z ${BASE_BRANCH+x} ]; then
echo "(BASE_BRANCH is not set. Using \"master\" by default.)"
base_branch="master"
else
base_branch=$BASE_BRANCH
fi
# Initialize the repository path.
REPOSITORY_PATH="origin"
# Check to see if the remote exists prior to deploying.
# If the branch doesn't exist create here as an orphan.
if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "$BRANCH" | wc -l)" -eq 0 ];
then
echo "Creating remote branch ${BRANCH} as it doesn't exist..."
git checkout $base_branch && \
git checkout --orphan $BRANCH && \
git rm -rf . && \
touch README.md && \
git add README.md && \
git commit -m "Initial ${BRANCH} commit" && \
git push $REPOSITORY_PATH $BRANCH
fi
# Check out the base branch to begin the deploy process.
git checkout $base_branch && \
# Build the project if a build script is provided.
echo
echo "Running build scripts..."
echo '= = ='
eval "$BUILD_SCRIPT" && \
if [ "$CNAME" ]; then
echo "Generating a CNAME file in the $FOLDER directory..."
echo $CNAME > $FOLDER/CNAME
fi
# Commit the data to Github.
echo
echo "Deploying to GitHub..."
echo '= = ='
git add -f $FOLDER && \
git commit -m "Deploy to ${BRANCH} from $base_branch" --quiet && \
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER $base_branch`:$BRANCH --force && \
git reset --hard HEAD^ && \
echo '- - -'
echo '(done)'
echo