Skip to content

Instantly share code, notes, and snippets.

@5minpause
Created July 5, 2013 15:12
Show Gist options
  • Save 5minpause/5935203 to your computer and use it in GitHub Desktop.
Save 5minpause/5935203 to your computer and use it in GitHub Desktop.
small sinatra app to listen for a post-receive hook and deploy my blog 5minutenpause.com
require 'sinatra'
require 'json'
post '/' do
if params && params[:payload]
push = JSON.parse(params[:payload])
commits = push['commits']
num_of_commits = push['commits'].length
last_commit_message = commits[num_of_commits-1]['message']
if last_commit_message =~ /publish/
output = `cd local_octopress_directory && git pull ; cd local_octopress_directory && bundle install ; cd local_octopress_directory && bundle exec rake -f local_octopress_directory/Rakefile gen_deploy RAILS_ENV=development 2>&1`
"deployed to site: #{output}"
else
'nothing to publish. doing nothing'
end
end
end
get '/' do
'nothing to see here.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment