-
Notifications
You must be signed in to change notification settings - Fork 10
/
deploy.sh
executable file
·67 lines (55 loc) · 2.56 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
#!/bin/bash
# clear and re-create the build directory
rm -rf build || exit 0;
mkdir build;
REPO="${GITHUB_REPO}"
EMAIL="${GIT_EMAIL}"
TOKEN="${GH_TOKEN}"
if [ -z "${REPO}" ]; then
REPO="[email protected]:ionwg/ionwg.github.io.git"
printf '%s\n' "GITHUB_REPO value not set - using default value ${REPO}"
fi
if [ -z "${EMAIL}" ]; then
EMAIL=$(git config user.email)
[ -z "${EMAIL}" ] && echo "Required GIT_EMAIL or 'git config user.email' value has not been set." && exit 1
printf '%s\n' "GIT_EMAIL value not set - defaulting to output of 'git config user.email': ${EMAIL}"
fi
if [ -z "${TOKEN}" ]; then
TOKEN=$(git config --local github.token)
[ -z "${TOKEN}" ] && echo "Required GH_TOKEN or 'git config --local github.token' value has not been set." && exit 1
printf '%s\n' "GH_TOKEN value not set - defaulting to output of 'git config --local github.token': <hidden>"
fi
set -e # exit with nonzero exit code if anything fails from here on
# If GITHUB_REPO is an ssh URI, change it to the GitHub equivalent https URL:
REPO=$(echo "${REPO}" | sed 's/^[email protected]:/https:\/\/github.com\//')
# now ensure that the https:// scheme prefix is stripped so we can add in the token:
REPO=$(echo "${REPO}" | sed 's/^https:\/\///')
# now add in the scheme and token:
REPO="https://${TOKEN}@${REPO}"
# run our build script - this will create the rendered HTML that we'll push to the site
./build.sh
# if Travis is building a pull request to master, don't deploy - we only want to deploy
# when data is actually merged to master:
if [ -n "${TRAVIS_PULL_REQUEST}" ] && (( "${TRAVIS_PULL_REQUEST}" > 0 )); then
printf '%s\n' "Pull request detected. Not deploying site master."
exit 0;
fi
# copy over any other site assets that need to be in the site:
cp draft-ion.html build
cp googlee4449629928490e1.html build
cp CNAME build
# go to the build directory and create a *new* Git repo
cd build
git init
# inside this git repo we'll pretend to be a new user
git config user.email "${EMAIL}"
git config user.name "Travis CI on behalf of ${EMAIL}"
# The first and only commit to this new Git repo contains all the
# files present with the commit message "Deploy to GitHub Pages".
git add .
git commit -m "Deploy to GitHub Pages"
# Force push from the current repo's master branch to the remote
# repo's master branch. (All previous history on the remote master branch
# will be lost, since we are overwriting it.) We redirect any output to
# /dev/null to hide any sensitive credential data that might otherwise be exposed.
git push --force --quiet "${REPO}" master:master > /dev/null 2>&1