UNPKG

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