Skip to content

Commit

Permalink
Improve Travis cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohirafuji committed Sep 5, 2017
1 parent baaee41 commit 712683c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
elm-stuff
elm-stuff
node_modules
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ node_js: node

cache:
directories:
- elm-stuff/packages
- tests/elm-stuff/packages
- demo/elm-stuff/packages
- elm-stuff/build-artifacts
- tests/elm-stuff/build-artifacts
- demo/elm-stuff/build-artifacts
- node_modules
- sysconfcpus

os:
Expand All @@ -17,12 +18,15 @@ env:
global:
- ELM_VERSION="0.18.0"
- ELM_TEST_VERSION="0.18.7"
- SYSCONFCPUS="${TRAVIS_BUILD_DIR}/sysconfcpus/bin/sysconfcpus -n 2"
- ELM="${TRAVIS_BUILD_DIR}/node_modules/.bin/elm"
- ELM_TEST="node ${TRAVIS_BUILD_DIR}/node_modules/elm-test/bin/elm-test"

before_install:
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

install:
- npm install -g elm@$ELM_VERSION elm-test@$ELM_TEST_VERSION
- npm install elm@$ELM_VERSION elm-test@$ELM_TEST_VERSION
# Faster compile on Travis.
- |
if [ ! -d sysconfcpus/bin ];
Expand All @@ -35,6 +39,5 @@ install:
fi
script:
- $TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 elm-test
- bash ./demo/deploy-gh-pages.sh

- $SYSCONFCPUS $ELM_TEST
- bash ./demo/deploy.sh
84 changes: 0 additions & 84 deletions demo/deploy-gh-pages.sh

This file was deleted.

File renamed without changes.
60 changes: 60 additions & 0 deletions demo/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# From https://gist.github.com/domenic/ec8b0fc8ab45f39403dd

set -e # Exit with nonzero exit code if anything fails

SOURCE_BRANCH="master"
TARGET_BRANCH="gh-pages"
TEMP_FOLDER="${TRAVIS_BUILD_DIR}/temp"
ENCRYPTION_LABEL="2e639d5f7f73"
UGLIFYJS="node ${TRAVIS_BUILD_DIR}/node_modules/uglify-js/bin/uglifyjs"

# Save some useful information
REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
SHA=`git rev-parse --verify HEAD`

# Clone the existing gh-pages for this repo into TEMP_FOLDER
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deploy)
echo "Building and deploying demo"
echo "Target: ${TARGET_BRANCH} branch"
# git clone $REPO $TEMP_FOLDER
# cd $TEMP_FOLDER
# git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH

# Run our compile script
echo "Compiling into ${TEMP_FOLDER}/"
npm install uglify-js
cd demo
$SYSCONFCPUS $ELM make Main.elm --output $TEMP_FOLDER/elm.js --yes
sed -i -e 's/\/_compile\/Main.elm/elm.js/g' index.html
cp index.html $TEMP_FOLDER/index.html
$UGLIFYJS $TEMP_FOLDER/elm.js --output $TEMP_FOLDER/elm.js

cd $TRAVIS_BUILD_DIR
git checkout $TARGET_BRANCH
cp $TEMP_FOLDER/* $TRAVIS_BUILD_DIR

# Git commands
git config user.name "Travis CI"
git config user.email "pablohirafuji@gmail.com"
git add index.html elm.js
git commit -m "Deploy to GitHub Pages: ${SHA}"

# Get the deploy key by using Travis's stored variables to decrypt deploy-key.enc
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../demo/deploy-key.enc -out deploy-key -d

chmod 600 deploy-key
eval `ssh-agent -s`
ssh-add deploy-key

# Now that we're all set up, we can push.
git push $SSH_REPO $TARGET_BRANCH

echo "Deployed successfully."
exit 0

0 comments on commit 712683c

Please sign in to comment.