safe-bundle-update 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03e26b4b04201b355043bd0bfa2c14fadd1b5e63
4
+ data.tar.gz: 6dc56c6128f4e94f010a1711776c25632647d411
5
+ SHA512:
6
+ metadata.gz: e739d2f758c09c65efacef3e93f9b9795d1c2b9cd2b4bfc77a60ac9ebe6e217d3c9d642f4a36738ab6849b0423ff173af3d2133f5b8040138c3d81fb2101a008
7
+ data.tar.gz: 1f3c3ca4ea851f976a3d2c83c4ae85719338117a2d05d5c9e97fb2cfef5d6d43aeadad905b47582fc3086f6bc51910e90ffd027d18cf6909d05a2855c4160e5c
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'safe-bundle-update'
4
+ SafeBundleUpdate.start(*ARGV)
@@ -0,0 +1,52 @@
1
+ require 'colorize'
2
+
3
+ class SafeBundleUpdate
4
+ def self.start(*commands)
5
+ excludes = []
6
+ gems = fetch_gems
7
+ puts "#{gems.size} gems to be updated"
8
+
9
+ while gem = gems.detect { |name| !excludes.include?(name) }
10
+ puts "Updating #{gem}..."
11
+ next excludes << gem unless try_system("bundle update #{gem}", gem)
12
+ if `git status | grep "nothing to commit, working tree clean" | wc -l`.strip.to_i == 1
13
+ excludes << gem
14
+ puts "Nothing changed".red
15
+ next
16
+ end
17
+ next excludes << gem unless commands.all? { |cmd| try_system(cmd, gem, color: :yellow, null: false) }
18
+ try_system("git add .", gem)
19
+ try_system("git commit -m 'Updating #{gem}'", gem, color: :green)
20
+ gems = fetch_gems
21
+ end
22
+ end
23
+
24
+ class << self
25
+
26
+ private
27
+
28
+ def try_system(cmd, gem, color: nil, null: !ENV['SHOW_OUTPUT'])
29
+ puts "Running `#{cmd}` for #{gem}"
30
+
31
+ ok = system(cmd, out: File::NULL)
32
+
33
+ if !ok
34
+ puts "`#{cmd}` failed, reverting and excluding".red
35
+ system("#{cmd} > /dev/null") if !null
36
+ system("git add Gemfile**")
37
+ system("git checkout Gemfile")
38
+ system("git checkout Gemfile.lock")
39
+ false
40
+ elsif color
41
+ puts "Ran `#{cmd}` for #{gem}".colorize(color)
42
+ true
43
+ else
44
+ true
45
+ end
46
+ end
47
+
48
+ def fetch_gems
49
+ `bundle outdated`.lines.grep(/\*/).map { |l| l.split[1] }
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safe-bundle-update
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "`bundle update` updates all your gems, this safely updates yours gems
14
+ one by one"
15
+ email: dorian@doma.io
16
+ executables:
17
+ - safe-bundle-update
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/safe-bundle-update
22
+ - lib/safe-bundle-update.rb
23
+ homepage: https://github.com/Dorian/safe-bundle-update
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.8
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Update gems one by one, running tests and commiting changes
47
+ test_files: []