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
# http://github.com/appden/appden.github.com/blob/master/Rakefile

task :default => :server

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

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

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"
      end
    end
  end
  if ( !xed ) then
    sh 'git push'
    puts "Committed files were pushed"
  end
end

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

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