Using Travis to deploy Middleman on Github pages

Posted by Jérémy Jousse on February 08, 2016

I recently created a blog scaffold for a friend of my using Middleman. Using Github pages in addition to Middleman allows my friend to host his blog without any charge. This is great but my friend is not a geek, and he does not hold back all the Middleman boring commands to commit, generate, and deploy his blog.

I finaly found a content editor for GitHub designed for managing websites. With a little my time of configuring, my friend has finally a GUI editor to handle his Middleman blog.

The last challenge was to automate the build and deployment of his blog after each commit.

The middleman extention directory list 8 deployment gems, I've chosen middleman-deploy which is an official contribution form Middleman team. This gem is also extermly simple to use with github pages.

Setup Middleman

First add the middleman-deploy gem to your Gemfile

gem 'middleman-deploy'

Then activate the deploy pluggin in Middleman config.rb file

activate :deploy do |deploy|
  deploy.deploy_method = :git
  deploy.build_before = true

This activates the deploy pluggin to deploy using github pages. Find the complet middleman-deploy documentation on his Github project

Setup Travis

You can now log to Travis, then activate Travis integration to you project. My Photo

Connect Travis to Github

Now you have to generate a Github Personal Access Token form your Github Tokens Settings page My Photo

Then add your Github Personal Access Token to your Travis project settings using Environment Variables. Your Github Personal Access Token will be "GH_TOKEN" Environment Variable (do not enable the "Display value in build log" option for this variable !). My Photo

Add Travis config file to Middleman

Now you can create a .travis.yml file.

language: ruby
  - 2.3.0
cache: bundler
  - git config --global '${GIT_NAME}'
  - git config --global '${GIT_NAME}'
  - git remote set-url origin https://<your-github-user>:${GH_TOKEN}<your-github-user>/<your-github-repository>.git
  - bundle exec middleman deploy

You now only have to commit and push your updates to see your Middleman website magically updated.


I found this so magic that I replay that configuration on this website. If you missed something you can have a look at my Middleman project.