Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby
require 'colorize'
abort('USAGE safe-bundle-update CMD') if ARGV.empty?
CMDS = ARGV
EXCLUDE = []
def try_system(cmd, gem, color: nil)
puts "Running `#{cmd}` for #{gem}".colorize(color)
ok = system(cmd, out: File::NULL)
if !ok
puts "`#{cmd}` failed, reverting and excluding".red
system("git add .")
system("git reset --hard")
EXCLUDE << gem
end
ok
end
gems = `bundle outdated`.lines.grep(/\*/).map { |l| l.split[1] }
puts "#{gems.size} gems to be updated"
while gem = gems.detect { |name| !EXCLUDE.include?(name) }
puts "Updating #{gem}..."
next unless try_system("bundle update #{gem}", gem)
next unless CMDS.all? { |cmd| try_system(cmd, gem) }
try_system("git add .", gem)
try_system("git commit -m 'Updating #{gem}'", gem, color: :green)
gems = `bundle outdated`.lines.grep(/\*/).map { |l| l.split[1] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment