UNPKG

1.94 kBapplication/x-shView Raw
1#!/bin/bash
2set -e # Exit with nonzero exit code if anything fails
3
4SOURCE_BRANCH="master"
5TARGET_BRANCH="gh-pages"
6
7function doCompile {
8 bundle exec jekyll build
9}
10
11# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
12if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
13 echo "Skipping deploy; just doing a build."
14 doCompile
15 exit 0
16fi
17
18# Save some useful information
19REPO=`git config remote.origin.url`
20SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
21SHA=`git rev-parse --verify HEAD`
22OUT=_gh_pages
23
24# Clone the existing gh-pages for this repo into dist/
25# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
26git clone $REPO $OUT
27cd $OUT
28git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
29cd ..
30
31# Clean out existing contents
32rm -rf $OUT/**/* || exit 0
33
34# Run our compile script
35doCompile
36
37# Now let's go have some fun with the cloned repo
38cd $OUT
39git config user.name "Travis CI"
40git config user.email "$COMMIT_AUTHOR_EMAIL"
41
42# If there are no changes to the compiled dist (e.g. this is a README update) then just bail.
43if git diff --quiet; then
44 echo "No changes to the output on this push; exiting."
45 exit 0
46fi
47
48# Commit the "changes", i.e. the new version.
49# The delta will show diffs between new and old versions.
50git add -A .
51git commit -m "Deploy to GitHub Pages: ${SHA}"
52
53# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
54ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
55ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
56ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
57ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
58openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d
59chmod 600 ../deploy_key
60eval `ssh-agent -s`
61ssh-add ../deploy_key
62
63# Now that we're all set up, we can push.
64git push $SSH_REPO $TARGET_BRANCH