Publishing a Jekyll based static website on GitHub Pages is quite easy once it is setup properly. This way you can trigger a publish on a different branch every time a change is pushed into the GitHub repository.
I will describe how to do it using
rake-jekyll. For more detailed and probably updated information, please refer to the rake-jekyll documentation on the project page
If you already don’t have one, create a
Gemfile in your repository or update one you already have according to the following:
source 'https://rubygems.org' gem 'jekyll' gem 'rake' gem 'rake-jekyll'
Create or edit file
Rakefile in your repository:
require 'rake-jekyll' Rake::Jekyll::GitDeployTask.new(:deploy)
.travis.yml in your repository:
language: ruby sudo: false rvm: 2.2.0 script: bundle exec rake deploy
travis gem using shell:
$ gem install travis
Enable Travis CI for your github repository:
- if you already don’t have a Travis CI account, sign up for one.
- open your profile page on Travis
- find your github repository for the website and turn on the switch
- click on the repository settings
- enable the setting “Build only if .travis.yml is present.”
Generate a new personal access token on GitHub:
- Generate a new personal access token for your Github profile
public_reposcope, enter description and generate. You will need the token displayed on the page for the next step.
Encrypt the token using the following shell command (replace the
<token> part with your generated token from the previous step):
$ travis encrypt GH_TOKEN=<token> --add env.global
Following content will be added to your
env: global: secure: YOUR-ENCRYPTED-TOKEN
Commit your changes and push to GitHub. Travis will trigger a build and publish your website in a couple of minutes.