Skip to content

Commit

Permalink
Have Travis CI build static site from source files
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jul 22, 2018
1 parent 2031189 commit e9cca3a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ Gemfile.lock
node_modules
package.json
.idea/
deploy_key
17 changes: 17 additions & 0 deletions .travis.yml
@@ -0,0 +1,17 @@
language: ruby
branches:
only:
- source
rvm:
- 2.3.4
before_install:
- openssl aes-256-cbc -K $encrypted_1dd176ece64a_key -iv $encrypted_1dd176ece64a_iv -in deploy_key.enc -out deploy_key -d
before_script:
- chmod +x ./deploy.sh
script: bash ./deploy.sh
exclude:
- vendor
sudo: false
env:
global:
- COMMIT_AUTHOR_EMAIL: watir.team@gmail.com
4 changes: 3 additions & 1 deletion _config.yml
Expand Up @@ -116,6 +116,8 @@ exclude:
- Gemfile.lock
- LICENSE
- README.md
- CNAME
- deploy.sh
- deploy_key.enc
- deploy_key
include:
- _pages
59 changes: 59 additions & 0 deletions deploy.sh
@@ -0,0 +1,59 @@
#!/bin/bash

# https://ayastreb.me/deploy-jekyll-to-github-pages-with-travis-ci/
# https://gist.github.com/domenic/ec8b0fc8ab45f39403dd

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

SOURCE_BRANCH="source"
TARGET_BRANCH="master"

function doCompile {
bundle exec jekyll build
}

# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
echo "Skipping deploy; just doing a build."
doCompile
exit 0
fi

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

echo "Make sure source doesn't have _site data"
rm -rf _site

echo "Clone the existing code for this repo into _site/"
git clone $REPO _site

echo "Build content with Jekyll"
doCompile

echo "Set Git information"
cd _site
git config user.name "Travis CI"
git config user.email "$COMMIT_AUTHOR_EMAIL"

# If there are no changes to the compiled out (e.g. this is a README update) then just bail.
if git diff --quiet -- . ':(exclude)*.xml'; then
echo "No changes to the output on this push; exiting."
exit 0
fi

echo "Commit the changes"
# The delta will show diffs between new and old versions.
git add -A .
git commit -m "Deploy Generated Content from Travis Build ${TRAVIS_BUILD_NUMBER}"

echo "Set permissions for the Key"
chmod 600 ../deploy_key

echo "SSH Add key"
eval `ssh-agent -s`
ssh-add ../deploy_key

echo "Push to Repo"
git push $SSH_REPO
Binary file added deploy_key.enc
Binary file not shown.

0 comments on commit e9cca3a

Please sign in to comment.