UNPKG

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