-
Notifications
You must be signed in to change notification settings - Fork 12
/
deploy.sh
executable file
·45 lines (39 loc) · 1.07 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
#!/bin/bash
function try {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "!!!Error!!! with $1" >&2
exit $status
fi
return $status
}
# config
ENVIRONMENT="$1"
SUFFIX="-staging"
REMOTE="staging"
if [ "$ENVIRONMENT" == "production" ]; then
SUFFIX=""
REMOTE="origin"
fi
echo "Deploying to gobstones-web$SUFFIX (remote $REMOTE)..."
echo "Building project"
# build
rm -rf .tmp dist
try npx gulp # TODO: commitear a master para que no haya que instalar gulp global
# push to gh pages
current_branch=$(git branch | grep \* | cut -d ' ' -f2)
echo "Deleting temporary things..."
git branch -D deploy
git branch -D tmp-deploy
git remote remove $REMOTE
echo "Creating deploy commit..."
try git checkout -b deploy
try git add -Af dist/
try git commit -m "Deploy @ $(date +'%d/%m/%Y')"
echo "Creating deploy subtree commit..."
try git subtree split --prefix dist deploy -b tmp-deploy
echo "Pushing to remote..."
try git remote add $REMOTE "[email protected]:gobstones/gobstones-web$SUFFIX.git"
try git push -f $REMOTE tmp-deploy:gh-pages
git checkout "$current_branch"