Skip to content

Instantly share code, notes, and snippets.

@nvreynolds nvreynolds/heroku_deploy.rake Secret
Created Jul 16, 2014

Embed
What would you like to do?
Tddium post build - Heroku deploy
def cmd(c)
system c
end
namespace :tddium do
desc "post_build_hook"
task :post_build_hook do
if ENV['TDDIUM_CURRENT_BRANCH'] == "master"
# Heroku Deploy
#return unless ENV["TDDIUM_MODE"] == "ci"
return unless ENV["TDDIUM_BUILD_STATUS"] == "passed"
dir = File.expand_path("~/.heroku/")
heroku_email = ENV["HEROKU_EMAIL"]
heroku_api_key = ENV["HEROKU_API_KEY"]
app_name = ENV["HEROKU_APP_NAME"]
push_target = "git@heroku.com:#{app_name}.git"
FileUtils.mkdir_p(dir) or abort "Could not create #{dir}"
puts "Writing Heroku Credentials"
File.open(File.join(dir, "credentials"), "w") do |f|
f.write([heroku_email, heroku_api_key].join("\n"))
f.write("\n")
end
File.open(File.expand_path("~/.netrc"), "a+") do |f|
['api', 'code'].each do |host|
f.puts "machine #{host}.heroku.com"
f.puts " login #{heroku_email}"
f.puts " password #{heroku_api_key}"
end
end
puts "Pushing to Heroku: #{push_target}..."
cmd "git push #{push_target} master -f" or abort "could not push to #{push_target}"
puts "Running Heroku Migrations..."
cmd "heroku run rake db:migrate -a #{app_name}" or abort "aborted migrations"
puts "Restarting Heroku..."
cmd "bundle exec heroku restart -a #{app_name}" or abort "aborted heroku restart"
else
puts "Not deploying since not 'master' branch"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.