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:
- Enable Travis builds for your GitHub repository. Enable
Build only if .travis.yml is presentin the settings page
SURGE_TOKENvariables with the
- Create a build and test script, and commit it to your repository. For some reasons, Travis CI had issues with a few of my external links, so I disabled the external link checker with the
--disable-externaloption. Make sure you fix all the issues that
htmlprooferhas found until you see the
HTML-Proofer finished successfullymessage
#!/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.