-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
68 lines (52 loc) · 2.63 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
#!/bin/bash
# THANKS https://github.com/steveklabnik/automatically_update_github_pages_with_travis_example
echo -e "#####################################################"
echo -e " START DEPLOYING"
echo -e "#####################################################"
# stop executing if any errors occur, by default bash will just continue past any errors to run the next command
# stop executing if an unset variable is encountered, by default bash will use an empty string for the value of such variables.
set -o errexit -o nounset
# Here we ensure that we only deploy when we commit against the master branch,
# if not we just simply abort the deploy, no errors. So this way we can see the
# result of the tests when we make pull request between different branches or
# commit against a different branch than the master.
if [ "$TRAVIS_BRANCH" != "master" ]
then
echo "This commit was made against the $TRAVIS_BRANCH and not the master! No deploy!"
exit 0
fi
# This sets a variable, rev, with the short hash of HEAD.
# We'll use this later in a commit message.
rev=$(git rev-parse --short HEAD)
# We need to cd into wherever our website built.
# With Jekyll, it's _site. But do whatever.
cd dist
# First, we initialize a new git repository. Yes, a new one. You'll see.
git init
# We then set our user name and user email. This person will have done the commits that go to gh-pages.
# It's not a default branch, so don't worry, GitHub doesn't count these commits as contributions for your graph.
git config user.name "proustibat"
git config user.email "[email protected]"
# Next, we add a remote, named upstream, and we set it to our project.
# But we also interpolate that $GH_TOKEN variable,
# which will allow us to push to this repository later.
git remote add upstream "https://[email protected]/proustibat/demo-rellax.git"
git remote -v
# We then fetch it and reset to the gh-pages branch.
# Now, git sees this new repository as just some files
# that change your upstream gh-pages branch.
git fetch upstream
git reset upstream/gh-pages
# Sometimes, you'll need some extra files.
# A CNAME is common, which sets a custom domain up.
# You'll need to run whatever commands generate those files for you.
#echo "rustbyexample.com" > CNAME
# We then touch everything, so that git considers all of our local copies fresh.
touch .
git status
# We then add all changes, commit them, using our rev from earlier, and then push to upstream.
git add -A .
git commit -m "rebuild pages at ${rev}"
# The -q keeps this a bit more quiet, and you can control the noisiness
# of all these different git commands with a judicious sprinkling of -q.
git push upstream HEAD:gh-pages