Using Travis CI to build and deploy sites




I finally got around the time to use Travis CI for my Jekyll blog. Travis CI is a continuous integration service for projects hosted on GitHub.

For those who have used Jekyll, you would know that each time you make changes to your blog, you have to re-generate the static pages, perhaps test them, and then deploy the changes to your hosting provider, which in my case is Surge. Now, Travis CI does all that for me automatically whenever I push an update to GitHub!

Here’re what I did:

#!/usr/bin/env bash
set -e # halt script on error

bundle exec jekyll build
bundle exec htmlproofer ./_site --disable-external
# bundle exec htmlproofer ./_site
  • Update your Gemfile so that Travis can automatically install all the Ruby dependencies with bundle install. For example,
$ grep -v ^# Gemfile
source 'https://rubygems.org'

gem 'jemoji'
gem 'jekyll-redirect-from'
gem 'jekyll-paginate'
gem 'kramdown'
gem 'rouge'
gem 'html-proofer'
gem 'minitest'
gem 'html-pipeline'
language: ruby
rvm:
- 2.3.0 # ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

before_script:
 - chmod +x ./script/cibuild
 - npm install --global surge

script: ./script/cibuild

branches:
  only:
  - source

env:
  global:
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer

sudo: false # route your build to the container-based infrastructure for a faster build

after_success:
   surge -p ./_site/

When Travis CI detects a push to GitHub, it will set up a build environment in a clean VM, make ./script/cibuild an executable, install surge, run the script only on the source branch, and if the build is successful, deploy the blog to Surge.

That’s all you have to do. Hope you find these steps useful.

comments powered by Disqus

Related Posts

Downgrading Vagrant with Brew

Replacing Travis CI with Docker

Amazon EMR, Apache Spark, and Apache Zeppelin