Skip to content

Instantly share code, notes, and snippets.

@rafamanzo
Created August 31, 2015 15:47
Show Gist options
  • Save rafamanzo/7908d941a67216f0a465 to your computer and use it in GitHub Desktop.
Save rafamanzo/7908d941a67216f0a465 to your computer and use it in GitHub Desktop.
Updates gems. WIP
#!/usr/bin/env ruby
GEM_LINE_BEGINNING = " * "
def git_commit(current_gem_name)
puts "\tCommiting"
system("git commit -am \"Auto updated: #{current_gem_name}\" &> /dev/null")
end
def git_reset
system('git reset --hard &> /dev/null')
end
def gem_name_list
puts "\tListing"
outdated_raw = `bundle outdated`.split("\n")
outdated_gems = outdated_raw.delete_if { |line| !line.start_with?(GEM_LINE_BEGINNING)}
outdated_gems.map { |gem_line| gem_line.gsub(GEM_LINE_BEGINNING, '').split(" ")[0] }
end
def check_unit_tests(current_gem_name)
print "\tRunning tests..."
unless system('rake spec &> /dev/null')
STDERR.puts("ERROR: Failed to update #{current_gem_name}! Tests were broken!")
git_reset
exit(1)
else
print "OK\n"
end
end
puts "Prechecking the state:"
check_unit_tests("the whole application")
outdated_list = gem_name_list
puts "Running updates:"
current_package = 1
outdated_list.each do |gem_name|
puts "\t#{current_package}/#{outdated_list.count} - Updating #{gem_name}"
system("bundle update #{gem_name} &> /dev/null")
check_unit_tests(gem_name)
git_commit(gem_name)
current_package = current_package + 1
end
puts "Post processing:"
remaing_outdated_list = gem_name_list
puts "\tThe following gems could not be updated:"
remaing_outdated_list.each do |gem_name|
puts "\t\t#{gem_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment