forked from hibikir/engineering-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_prod.sh
executable file
·80 lines (57 loc) · 1.89 KB
/
update_prod.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
#!/bin/bash
# this is necessary because we use plugins not supported by GitHub Pages
set -e
origin="origin"
master="master"
pages="gh-pages"
develop="develop"
self=`basename $0`
: ${TMPDIR:=/tmp}
tmp_repo=$(mktemp -d -t $self)
tmp_site=$(mktemp -d -t $self-site)
echo "---> Updating gh-pages with master generated content"
ldir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$ldir"
echo "---> Determining remote url for $origin"
remote=$(git remote --verbose | awk "/^$origin/ { print \$2; exit 0 }")
echo "---> Fetching $origin"
git fetch "$origin"
echo "---> Changing to $master"
git checkout -B "$master" "$origin/$master"
echo "---> Merge changes from $develop branch into $master"
git merge -m "merging from $origin/$develop on `date`" $origin/$develop
echo "---> Getting commit SHA"
gitsha=$(git log | head -n1 | cut -d" " -f2)
echo "---> Building site from latest $master to $tmp_site"
jekyll build -d "$tmp_site"
echo "---> Cloning repo $remote to $tmp_repo"
git clone "$remote" "$tmp_repo"
echo "---> Changing to $tmp_repo"
cd "$tmp_repo"
echo "---> Changing to $pages branch"
git checkout "$pages"
echo "---> Removing content from $pages branch"
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "---> Copying new content into $pages branch"
cp -r $tmp_site/. .
touch .nojekyll
echo "---> Cleaning up jekyll build directory: $tmp_site"
rm -rf $tmp_site
echo "---> Publishing to $pages branch"
git add -A
git commit -m "publishing $master $gitsha build to $pages on `date`"
git push "$origin" "$pages"
echo "---> Changing back to original repo clone"
cd "$ldir"
echo "---> Cleaning up temp repo: $tmp_repo"
rm -rf "$tmp_repo"
echo "---> Changing back to $master branch"
git checkout "$master"
echo "---> Pushing $master branch to $origin"
git push "$origin" "$master"
echo "---> Switching back to $develop branch"
git checkout "$develop"
echo "---> Update complete"
exit 0