Skip to content

Instantly share code, notes, and snippets.

@novohispano
Created May 5, 2015 07:55
Show Gist options
  • Save novohispano/47b2918ece40efdfd79a to your computer and use it in GitHub Desktop.
Save novohispano/47b2918ece40efdfd79a to your computer and use it in GitHub Desktop.
Rake task to deploy to Heroku
desc "Print name"
task :name, [:name] do |t, arguments|
puts "My name is #{arguments[:name]}"
end
desc "Favorite animal"
task :animal, [:animal] do |t, arguments|
puts "My favorite animal is #{arguments[:animal]}"
end
namespace :deploy do
desc "Deploy application to Heroku"
task heroku: [:test, :push, :migrate]
task :test do
puts "Running the tests..."
if system("rake test:all") == false
puts "FAILURE: There is a problem with your tests."
break
end
puts "Done."
end
task :push do
puts "Pushing code to Heroku..."
if system("git push heroku heroku-ready:master") == false
puts "Failure: There was a problem when pushing to Heroku."
break
end
puts "Done."
end
task :migrate do
puts "Running migrations..."
if heroku("run rake db:migrate") == false
puts "FAILURE: There was a problem running your migrations."
break
end
puts "Done."
end
end
def heroku(command)
system("GEM_HOME='' BUNDLE_GEMFILE='' GEM_PATH='' RUBYOPT='' /usr/local/heroku/bin/heroku #{command}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment