Skip to content

Instantly share code, notes, and snippets.

@karangb
Created December 17, 2013 23:01
Show Gist options
  • Save karangb/8014257 to your computer and use it in GitHub Desktop.
Save karangb/8014257 to your computer and use it in GitHub Desktop.
post-receive github hook
#!/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby
# post-receive
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
from, to, branch = ARGF.read.split " "
# 2. Only deploy if master branch was pushed
if (branch =~ /master$/) == nil
puts "Received branch #{branch}, not deploying."
exit
end
# 3. Copy files to deploy directory
deploy_to_dir = File.expand_path('/var/www/theskiweek')
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"
# 4.TODO: Deployment Tasks
# i.e.: Run Puppet Apply, Restart Daemons, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment