Skip to content

Commit

Permalink
better error handling and reporting for heroku deploy task
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Cheung committed Apr 13, 2012
1 parent c7345b8 commit e744a45
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,39 @@ end
desc <<-DESC
Deploy application to heroku.
account=[name] if multiple heroku accounts
app=[name] if a different app name than directory
DESC
task :deploy do
system "git init 1>/dev/null"
remotes = `git remote`.chomp.split("\n")
if remotes.include? 'heroku'
`git push heroku master`
else
app_name = File.basename(File.expand_path("..", __FILE__))
command = ['heroku', 'apps:create']
app_name = ENV['app'].dup if ENV['app']
app_name ||= File.basename(File.expand_path("..", __FILE__))
app_name.gsub!('_', '-')
options = "-s cedar"
options << " --account=#{ENV['account']}" if ENV['account']
`heroku apps:create #{app_name} #{options}`
command << app_name
command << ['-s', 'cedar']
command << ['--account', ENV['account']] if ENV['account']
command.flatten!
puts "Executing: #{command * ' '}\n\n"
output = IO.popen(command << {:err => [:child, :out]}) do |io|
io.read
end
unless $?.success?
puts "Something went wrong.\n"
case output
when /No account specified/
puts "Ambiguous heroku accounts, try 'rake deploy account=youraccount'"
when /Name is already taken/
puts "App name already taken, try 'rake deploy app=another-app-name'"
else
puts output
end
else
puts output
end
end
end

Expand Down

0 comments on commit e744a45

Please sign in to comment.