This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
deploy.sh
executable file
·106 lines (89 loc) · 3.25 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
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
#!/usr/bin/env bash
set -e
# Variables
title="SeaSponge"
currentCommit=$(git rev-parse --verify HEAD)
if [[ -z "$TRAVIS_BRANCH" ]]; then
# TRAVIS_BRANCH is not set
currentBranch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
else
# TRAVIS_BRANCH is set
# Must be Travis CI
currentBranch="$TRAVIS_BRANCH"
fi
stableBranch="master"
deployBranch="gh-pages"
destDir="dist"
echo "=========="
echo "Preparing to Deploy $title!"
echo ""
if [ "$stableBranch" == "$currentBranch" ]; then
echo "You are on the correct stable branch, ${stableBranch}"
else
echo "You are on branch ${currentBranch} and not on the stable branch, ${stableBranch}!"
echo "Only the stable branch can be deployed."
exit 1;
fi
# Check if working tree is clean
echo "Checking if you have a clean working tree on this branch, ${currentBranch}"
if [[ -z $(git status -s) ]]; then
echo "Clean, let's continue!";
# Build to dist/
echo "Going to building the app into directory ${destDir}/"
grunt build
# Temporarily move bower_components/ directory
mkdir .tmp/ || true
mv bower_components/ .tmp/bower_components/ || true
# Checkout Deploy branch
echo "Preparing to checkout branch ${deployBranch}"
if [[ -z "$GH_TOKEN" ]]; then
# GH_TOKEN is not set
echo "Assuming you already have Git user name and email set"
else
# GH_TOKEN is set
# Must be in Travis CI
git config user.name "Travis-CI"
git config user.email "[email protected]"
fi
# Clear any uncommitted changes
git stash save --keep-index || true
git stash drop || true
# Fetch the deploy branch before checking out
git fetch origin "$deployBranch":"$deployBranch"
git checkout "$deployBranch"
# Clean deploy directory
echo "Cleaning up deploy branch by removing old build files"
find . -maxdepth 1 | grep -v "\./README\.md\|\./LICENSE\|\.git\|\./${destDir}\|\./node_modules\|\.tmp\|\.$" | xargs rm -r
# Move up dist/ to current directory for deploying
echo "Move the build files in ${destDir}/ up to the current directory for deploying"
mv ${destDir}/* .[^.]* . || true
echo "Remove directory ${destDir}/"
rm -r "${destDir}/"
echo "Adding changes to Git staging area"
git add --all
echo "Committing changes for build from commit ${currentCommit}"
git commit -m "Deploy build from branch ${currentBranch} for commit ${currentCommit}"
echo "Pushing changes"
if [[ -z "$GH_TOKEN" ]]; then
# GH_TOKEN is not set
git push origin "$deployBranch"
else
# GH_TOKEN is set
# Must be in Travis CI
git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" "${deployBranch}":"${deployBranch}"
fi
echo "Checking out original branch, ${currentBranch}"
git checkout "${currentBranch}"
# Move original bower_components/ back now that we are back in stable branch
rm -r bower_components/ || true # Remove the dist/bower_components/
mv .tmp/bower_components/ ./bower_components || true # Restore developer's bower_components/
echo "Done!"
echo "";
exit 0;
else
echo "Not clean! Please commit all uncommitted changes. Thank you.";
echo ""
git status
echo "";
exit 1;
fi