Skip to content

Instantly share code, notes, and snippets.

@johnbeynon
Created October 24, 2012 20:25
Show Gist options
  • Save johnbeynon/3948629 to your computer and use it in GitHub Desktop.
Save johnbeynon/3948629 to your computer and use it in GitHub Desktop.
TDDIUM > Heroku minus the Heroku gem
require 'heroku-api'
def cmd(c)
system c
end
namespace :tddium do
desc "post_build_hook"
task :post_build_hook do
# This build hook should only run after CI builds.
#
# There are other cases where we'd want to run something after every build,
# or only after manual builds.
return unless ENV["TDDIUM_MODE"] == "ci"
return unless ENV["TDDIUM_BUILD_STATUS"] == "passed"
# Assume that a Heroku API key is available in ENV['HEROKU_API_KEY']
heroku = Heroku::API.new
current_branch = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`.strip
app_name = ENV["HEROKU_APP_NAME"]
push_target = "[email protected]:#{app_name}.git"
puts "Adding Heroku addons"
required_addons = ['newrelic:standard','sendgrid:starter','pgbackups:auto-month']
required_addons.each do |addon|
begin # using a begin/rescue here in case the addon already exists in the app
heroku.post_addon(app_name, addon)
puts "#{addon} was added to #{app_name}"
rescue
puts "adding #{addon} skipped"
end
end
puts "Pushing to Heroku: #{push_target}..."
cmd "git push #{push_target} HEAD:master --force" or abort "could not push to #{push_target}"
puts "Running Heroku Migrations..."
heroku.post_ps(app_name, 'run rake db:migrate')
puts "Restarting Heroku..."
heroku.post_ps_restart(app_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment