Skip to content

Instantly share code, notes, and snippets.

Embed
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: https://travis-ci.org/dleidert/dleidert.github.io/builds. 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.

branches:
  only: master

Further the file disables notification emails for successful builds.

notifications:
  email:
    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

exclude:
  - ".git*"
  - .travis.yml
  - README.md

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/dleidert.github.io/_config.yml
            Source: /home/travis/build/dleidert/dleidert.github.io
       Destination: /home/travis/build/dleidert/dleidert.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
             Error: could not read file /home/travis/build/dleidert/dleidert.github.io/vendor/bundle/ruby/2.1.0/gems/jekyll-3.6.2/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb: Invalid date '<%= Time.now.strftime('%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.
             ERROR: YOUR SITE COULD NOT BE BUILT:
                    ------------------------------------
                    Invalid date '<%= Time.now.strftime('%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:

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

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

language: ruby
sudo: false
cache:
apt: true
bundler: true
directories:
- $TRAVIS_BUILD_DIR/tmp/.htmlproofer
notifications:
email:
on_success: never
branches:
only: master
env:
global:
- JEKYLL_ENV=production
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
addons:
apt:
packages:
- libcurl4-openssl-dev # resolve SSL issue of htmlproofer
rvm:
- 2.1
- 2.3
- 2.4
- 2.5
script:
- bundle exec jekyll build --trace
# https://github.com/gjtorikian/html-proofer/wiki/Using-HTMLProofer-From-Ruby-and-Travis
- bundle exec htmlproofer ./_site
# --check-external-hash
# --check-opengraph
# --check-sri
# --check-html
# --check-img-http
# --enforce-https
--timeframe 4w
exclude:
- Gemfile
- Gemfile.lock
- node_modules
- vendor/
- .travis.yml
- ".git*"
- README.md
source 'https://rubygems.org'
gem "github-pages", ">=177"
platforms :ruby_21 do
gem "rb-inotify", "~> 0.9"
gem "nokogiri", "~> 1.9"
end
group :test do
gem "html-proofer"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment