My goal for this site is to make it as easy for me to use as possible. That’s why I’m using Jekyll (which I’ll blog about another time). I also want to automate as much of the blogging, version control, and deployment as possible. Up until today I was using a simple rsync alias to get the new files on the “live” hosted server. But I thought it would be more fun and more convenient to have a little more automation, so I scoured GitHub for some good examples and found one written by Scott Kyle, which I took and modified.

My favorite part is the rake deploy command. If I have uncommitted changes in the site repo, it’ll abort the Rake operation and open GitX so I can commit my recent work. If everything is committed, it’ll build the files, run git push, and then do the rsync update.

# Adapted from Scott Kyle's Rakefile

task :default => :server

desc 'Build site with Jekyll'
task :build do
  jekyll '--no-server --no-auto'

desc 'Build and start server with --auto'
task :server do
  jekyll '--server --auto'

desc 'git commit or push'
task :gitx do
  xed = false
  IO.popen('git status') do |io|
    io.each_line do |line|
      if ( line =~ /^#\s*modified:/ && !xed ) then
        sh 'gitx'
        xed = true
        raise "\n!!! Do a git commit first !!!\n\n"
  if ( !xed ) then
    sh 'git push'
    puts "Committed files were pushed"

desc 'Build and deploy'
task :deploy => [:build, :gitx] do
  sh 'rsync -auz --progress _site/ [email protected]:/path/to/file/'

def jekyll(opts = '')
  sh 'rm -rf _site'
  sh 'jekyll ' + opts