-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
70 lines (52 loc) · 2.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -o errexit -o nounset
pr_revision=$(git rev-parse --short HEAD)
# If you want to check what environment variables are available, use this instead of a normal printenv to avoid leaking GH_TOKEN
#printenv | grep "^TRAVIS"
if [ "$TRAVIS_PULL_REQUEST" != "false" -a "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then
repo="findmeawalk-ci/builds"
rawgit_test_url="https://rawgit.com/${repo}/${TRAVIS_PULL_REQUEST_BRANCH}/"
build_branch=${TRAVIS_PULL_REQUEST_BRANCH}
deploy_branch=${TRAVIS_PULL_REQUEST_BRANCH}
# rerun build with the correct base path
sed -i "s/https:\/\/findmeawalk\.com\//${rawgit_test_url//\//\\/}/" package.json
npm run build
should_leave_pr_comment=1
elif [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
repo="rhokbrisbane/oxfam-trailwalker"
build_branch=${TRAVIS_BRANCH}
deploy_branch="gh-pages"
else
echo "Only deploying local pull requests or master"
exit 0
fi
echo "Deploying branch ${deploy_branch} at ${pr_revision} to ${repo}"
mkdir deploy
cd deploy
git init
git config user.name "Findmeawalk Bot"
git config user.email "[email protected]"
git remote add upstream "https://${GH_TOKEN}@github.com/${repo}.git"
git fetch upstream
# Checkout (if existing), or create a new branch and post a comment saying where to find it
if ! git checkout ${deploy_branch}; then
git checkout -b ${deploy_branch}
if [ $should_leave_pr_comment ]; then
curl -i \
-u "findmeawalk-ci:${GH_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"body": "Test this at '${rawgit_test_url}'"}' \
"https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments"
fi
fi
echo "Cleaning current directory"
git rm -rf --ignore-unmatch .
cp -R ../build/* .
# Note the current deploy sha/date
echo -n "<!-- ${pr_revision} - $(date) -->" >> index.html
echo "Adding files"
git add -A .
git commit -m "Deploy branch ${build_branch} at ${pr_revision}"
echo "Pushing branch"
# this needs to use -q or it leaks the GH_TOKEN in the public travis log
git push -q upstream HEAD:${deploy_branch}