Setting Up Travis CI for My Github Pages Site

This Page is Deprecated

I am no longer using Travis CI or Github Pages for this site. I started out on Github Pages, but I am now using Netlify, for a couple reasons:

  • Private repo support
  • Deployment previews

I have a new setup to validate the site, which I will probably post about at some point.

References:

1) Enable Travis builds for the Github repo

Enable this on your travis-ci.org profile page:

screenshot

Optionally click the gear icon to configure more things:

screenshot

2) Add the .travis.yml file in the project root:

.travis.yml
language: ruby
rvm:
- 2.2.0
script: bundle exec rake test
env:
  global:
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true

A couple things here:

3) Create a Rakefile in the project root, to automate build and test

Rakefile
require 'html-proofer'

# rake test
desc "build and test website"
task :test do
  sh "bundle exec jekyll build"
  HTMLProofer.check_directory("./_site", http_status_ignore: [999]).run
end

There is a known issue that LinkedIn articles return status code 999, which causes html-proofer to fail.4 That’s why I added http_status_ignore: [999].

4) Add the gems to your Gemfile

In a :test group:

Gemfile
source 'https://rubygems.org'

gem 'github-pages', group: :jekyll_plugins

# test the build
group :test do
  gem 'rake'
  gem 'html-proofer'
end

5) Test that this works locally

$ bundle install
$ bundle exec rake test
bundle exec jekyll build
(blah blah)
rake aborted!
HTML-Proofer found 18 failures!

Then after fixing all those failures, run again and it should show:

HTML-Proofer finished successfully.

6) Check that this is working on travis-ci

push

If you configured this earlier to build pushes, push whatever branch you’re committing this to. May have to fix a few issues to get it to green:

screenshot

And it should also show that it passed on github:

screenshot

pull request

Submit a pull request, and it should show that it passed:

screenshot

7) Add the badge thing to your README.md file

Merge that PR, and Travis should build the master branch.

On your repo page (https://travis-ci.org/mikrostew/mikrostew.github.io in my case), click the badge that now shows “build | passing”. Select the markdown option to get the code for that:

screenshot

Paste that code in the README.md, and you will see that badge on your project page:

screenshot

8) Get notifications on Slack

Start here, and click “new Travis CI integration”. Go through that to setup the channel that gets the notifications.

Before adding the config to .travis.yml it should be encrypted, since it contains an API token. This page explains how to do that:

$ travis encrypt [channel]:[api-token]
Please add the following to your .travis.yml file:

  secure: "CV7krTfkKRre...LdieyKfo="

Then add that to .travis.yml:

.travis.yml
...
notifications:
  slack:
    secure: "CV7krTfkKRre...LdieyKfo="

And the next time I push something, it sends a notification in Slack:

screenshot

All done!


Notes

  1. This is in a note under the Installation section here: https://github.com/gjtorikian/html-proofer#installation 

  2. https://docs.travis-ci.com/user/languages/ruby/ 

  3. http://rubies.travis-ci.org/ lists all of the available precompiled Rubies for Travis-CI 

  4. https://github.com/gjtorikian/html-proofer/issues/215 was closed, with workarounds described in the comments