Skip to content

Instantly share code, notes, and snippets.

@jgarber
Last active December 29, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber/7646297 to your computer and use it in GitHub Desktop.
Save jgarber/7646297 to your computer and use it in GitHub Desktop.
namespace :bundle do
def intersection
return @outdated if @outdated
@outdated = `bundle outdated`
@outdated = @outdated.split("\n").select{|line| line.include?("*")}
@outdated = @outdated.map{|gem| gem.match(/\* ([a-zA-Z0-9_-]+) /)[1]}
app_gems = File.readlines("Gemfile").select{|line| line.include?("gem ")}
app_gems = app_gems.map{|gem| gem.match(/gem '([a-zA-Z0-9_-]+)/)[1]}
@outdated = @outdated.select{|outdated_gem| app_gems.include?(outdated_gem)}
end
desc "Update each gem in 'bundle outdated' if it also appears in the Gemfile and run rake after each update"
task :update do
if intersection.any?
puts "Outdated gems that we depend on:\n#{intersection.join("\n")}\n"
intersection.each do |gem|
puts "Updating #{gem}"
puts `bundle update #{gem}`
puts `bundle exec rake`
if $? == 0
puts `git add Gemfile.lock`
puts `git commit -m "update #{gem} gem"`
else
puts "The tests failed for gem: #{gem}"
puts `git checkout Gemfile.lock`
end
end
else
puts "Nothing outdated."
end
end
desc "Show the gems from 'bundle outdated' that also appear in the Gemfile"
task :outdated do
if intersection.any?
puts "Outdated gems that we depend on:\n#{intersection.join("\n")}\n"
else
puts "Nothing outdated."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment