Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Build your github page on TRAVIS

Setting up TRAVIS CI for GitHub Pages

I recently set up TRAVIS CI support for my personal github pages. There are some github and jekyll support pages, that cover the basics. Unfortunately I ran into several build failures and issues not covered there until the builds finally succeeded. The following sections cover the issues and their solutions.

The results can be seen here: I'm planning to add support for different ruby versions. This will probably require different Gemfile variants.

Please note, that I don''t use TRAVIS to deploy the result to github. I'm just testing the build to debug issues. But there is plenty of documentation that covers this issue.

Notes for .travis.yml

The .travis.yml file below can be re-used without modification as long as github pages live on the master branch. If that is not the case, remove or adjust the branches directive.

  only: master

Further the file disables notification emails for successful builds.

    on_success: never

The package libcurl4-openssl-dev needs to be installed to fix SSL errors like this:

  *  External link https://[..] failed: response code 0 means something's wrong.
             It's possible libcurl couldn't connect to the server or perhaps the request timed out.
             Sometimes, making too many requests at once also breaks things.
             Either way, the return message (if any) from the server is: SSL connect error

The commented htmlproofer command in the script directive is inspired by this wiki page. Add these options if you like.

Notes for Gemfile

The Gemfile below covers the installation of all required Ruby gems including the jekyll plugins my site uses. My first build attempts failed with these errors:

ERROR:  Error installing jekyll:
	The last version of rb-inotify (~> 0.9, >= 0.9.7) to support your Ruby & RubyGems was 0.9.10. Try installing it with `gem install rb-inotify -v 0.9.10` and then running the current command again
	rb-inotify requires Ruby version >= 2.2. The current ruby version is 2.1.0.
ERROR:  Error installing html-proofer:
	The last version of nokogiri (~> 1.9) to support your Ruby & RubyGems was 1.9.1. Try installing it with `gem install nokogiri -v 1.9.1` and then running the current command again
	nokogiri requires Ruby version >= 2.3.0. The current ruby version is 2.1.0.

So this is probably due to using rvm: 2.1 in .travis.yml. To install the compliant versions of rb-inotify and nokogiri, the required versions for these gems were added to the Gemfile.

Notes for _config_yml

If the _config.yml file contains a custom exclude: directive like this

  - ".git*"
  - .travis.yml

this directive overwrites the default one and might lead to a build failure with the following error:

$ bundle exec jekyll build
Configuration file: /home/travis/build/dleidert/
            Source: /home/travis/build/dleidert/
       Destination: /home/travis/build/dleidert/
 Incremental build: disabled. Enable with --incremental
             Error: could not read file /home/travis/build/dleidert/ Invalid date '<%='%Y-%m-%d %H:%M:%S %z') %>': Document 'vendor/bundle/ruby/2.1.0/gems/jekyll-3.6.2/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb' does not have a valid date in the YAML front matter.
                    Invalid date '<%='%Y-%m-%d %H:%M:%S %z') %>': Document 'vendor/bundle/ruby/2.1.0/gems/jekyll-3.6.2/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb' does not have a valid date in the YAML front matter.
The command "bundle exec jekyll build" exited with 1.

Due to overwriting the default values, these need to be added to the exclude directive:

  - Gemfile # default
  - Gemfile.lock # default
  - node_modules # default
  - vendor/ # default is vendor/bundle/, vendor/cache/, vendor/gems/, vendor/ruby/
  - ".git*"
  - .travis.yml

There is no need to add them, if the _config.yml file does not containan exclude: directive.

language: ruby
sudo: false
apt: true
bundler: true
- $TRAVIS_BUILD_DIR/tmp/.htmlproofer
on_success: never
only: master
- JEKYLL_ENV=production
- libcurl4-openssl-dev # resolve SSL issue of htmlproofer
- 2.1
- 2.3
- 2.4
- 2.5
- bundle exec jekyll build --trace
- bundle exec htmlproofer ./_site
# --check-external-hash
# --check-opengraph
# --check-sri
# --check-html
# --check-img-http
# --enforce-https
--timeframe 4w
- Gemfile
- Gemfile.lock
- node_modules
- vendor/
- .travis.yml
- ".git*"
source ''
gem "github-pages", ">=177"
platforms :ruby_21 do
gem "rb-inotify", "~> 0.9"
gem "nokogiri", "~> 1.9"
group :test do
gem "html-proofer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment