Setting Up Travis CI for My Github Pages Site
- Jekyll’s docs on Travis-CI
- This post about Jekyll config (the “Adding Tests” section)
- The html-proofer README
1) Enable Travis builds for the Github repo
Enable this on your travis-ci.org profile page:
Optionally click the gear icon to configure more things:
2) Add the .travis.yml file in the project root:
language: ruby rvm: - 2.2.0 script: bundle exec rake test env: global: - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
A couple things here:
- Jekyll recommends setting
true, and according to the html-proofer docs that speeds up CI builds1
- Ruby 2.4.0 is the current stable version at this time,
but travis only supports versions up to 2.2.02 (edit: apparently this is no longer the case3)
3) Create a Rakefile in the project root, to automate build and test
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: ).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
4) Add the gems to your 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
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:
And it should also show that it passed on github:
Submit a pull request, and it should show that it passed:
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:
Paste that code in the README.md, and you will see that badge on your project page:
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
... notifications: slack: secure: "CV7krTfkKRre...LdieyKfo="
And the next time I push something, it sends a notification in Slack:
This is in a note under the Installation section here: https://github.com/gjtorikian/html-proofer#installation ↩
https://github.com/gjtorikian/html-proofer/issues/215 was closed, with workarounds described in the comments ↩