-
Notifications
You must be signed in to change notification settings - Fork 182
/
deploy.sh
executable file
·49 lines (40 loc) · 1.31 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
#!/bin/bash
SOURCE_BRANCH=`git rev-parse --abbrev-ref HEAD`
DEV_HASH=`git log --format='%H' -n 1`
DEV_PRETTY_HASH=`git log --pretty=format:'%h' -n 1`
REMOTE_NAME=`git remote -v | head -n1 | awk '{print $2}' | sed -e 's/.*\/\(.*\)\.git/\1/'`
if [ $# -ge 1 ]; then
DEST_BRANCH=$1
else
DEST_BRANCH=master
fi
if [ "$SOURCE_BRANCH" = "$DEST_BRANCH" ]; then
echo "You can't deploy to $DEST_BRANCH from $SOURCE_BRANCH"
exit 1
fi
BASE_URL=""
if [ $# -ge 2 ]; then
BASE_URL=$2
else
echo "f $REMOTE_NAME"
if [[ $REMOTE_NAME =~ github.io$ ]]; then
BASE_URL=""
else
BASE_URL="\/$REMOTE_NAME"
fi
fi
sed -i -pie "s/\(deploy_version: \)\(\".*\"\)/\1\"$DEV_PRETTY_HASH\"/g" _config.yml
mv _config.yml-pie _config.yml-pie-deploy #just for debug purposes
sed -i -pie "s/\(baseurl: \)\(\".*\"\)/\1\"$BASE_URL\"/g" _config.yml
mv _config.yml-pie _config.yml-pie-baseurl # just for debug purposes
cat _config.yml | grep "deploy_version"
cat _config.yml | grep "baseurl"
jekyll build
rm -rf _config.yml-pie-deploy
rm -rf _config.yml-pie-baseurl
git checkout _config.yml
git checkout $DEST_BRANCH
cp -r _site/* . && rm -rf _site/ es/_posts pt_BR/_posts deploy.sh _plugins/ .idea/
git add --all . && git commit -m "Regenerate files ( $DEV_HASH )"
git checkout $SOURCE_BRANCH && git clean -f -d
mkdir _site/ && jekyll build