Last active
December 29, 2015 08:49
-
-
Save jgarber/7646297 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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