Skip to content

Instantly share code, notes, and snippets.

@fancyremarker
Created July 9, 2012 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fancyremarker/3076379 to your computer and use it in GitHub Desktop.
Save fancyremarker/3076379 to your computer and use it in GitHub Desktop.
Heroku::Rake::Task wrapper to work around exit status issue in `heroku run`
module Heroku
module Rake
class Task
attr_accessor :name
def initialize(name)
@name = name
end
def self.[](name)
Heroku::Rake::Task.new(name)
end
def execute(options = {})
cmd = "heroku run \"rake #{name}"
cmd += "; echo \\$?\""
cmd += "#{options[:app] ? " --app #{options[:app]}" : ""}"
stdout = `#{cmd}`
$stdout.puts stdout.lines.to_a[0...-1]
exit_status = stdout.lines.to_a.last.chomp.to_i
raise "Heroku task #{name} failed with exit status #{exit_status}" unless exit_status == 0
end
end
end
end
namespace :heroku
desc "Run example task on remote Heroku"
task "example_task" do
Heroku::Rake::Task["example_task"].execute({ :app => "example-app" })
end
end
@fancyremarker
Copy link
Author

This is a quick hack to address heroku/legacy-cli#186, the symptom of which is heroku rake commands failing remotely but returning a successful exit status locally. Include the above Heroku module snippet in one of your lib/tasks/*.rake files, and then invoke a Heroku rake task from within any Rake task, a la:

Heroku::Rake::Task["some:task"].execute({ :app => "some-app" })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment