bundler-auto-update 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -3
- data/README.md +63 -0
- data/features/bundler_auto_update.feature +16 -8
- data/lib/bundler_auto_update.rb +32 -20
- data/lib/bundler_auto_update/version.rb +1 -1
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/gem_updater_spec.rb +18 -4
- data/spec/unit/gemfile_spec.rb +10 -1
- metadata +5 -4
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# bundler-auto-update
|
2
|
+
|
3
|
+
`bundler-auto-update` is a ruby gem that updates the gems listed in your Gemfile to the latest version that does not break your system.
|
4
|
+
|
5
|
+
`bundler-auto-updates` iterates over the gems listed in your Gemfile. It updates them to their latest patch, then minor, then major version. It runs your test suite and it commit changes if successfull or revert changes otherwise.
|
6
|
+
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
gem install bundler-auto-update
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
bundle-auto-update
|
15
|
+
|
16
|
+
The default test suite command is `rake`. You can specify a custom one with the `-c` option
|
17
|
+
|
18
|
+
bundle-auto-update -c rake test:all
|
19
|
+
|
20
|
+
## Sample output
|
21
|
+
|
22
|
+
<pre>
|
23
|
+
$> bundle-auto-update -c rake spec features
|
24
|
+
|
25
|
+
Updating devise
|
26
|
+
- Updating to patch version 1.1.9
|
27
|
+
- Test suite ran successfully.
|
28
|
+
- Committing changes
|
29
|
+
|
30
|
+
- Updating to minor version 1.4.7
|
31
|
+
- Test suite failed to run.
|
32
|
+
- Reverting changes
|
33
|
+
|
34
|
+
Updating rspec
|
35
|
+
- Updating to patch version 2.5.1
|
36
|
+
# [...]
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
$> git log
|
41
|
+
02cfb8c Auto update parallel to version 0.5.9 (16 hours ago) <Hudson>
|
42
|
+
ff39287 Auto update cucumber to version 1.1.0 (16 hours ago) <Hudson>
|
43
|
+
3502a14 Auto update cucumber to version 0.10.7 (16 hours ago) <Hudson>
|
44
|
+
2ff938c Auto update cucumber to version 0.9.4 (17 hours ago) <Hudson>
|
45
|
+
800ad84 Auto update hpricot to version 0.8.4 (17 hours ago) <Hudson>
|
46
|
+
5c92bf0 Auto update whenever to version 0.6.8 (17 hours ago) <Hudson>
|
47
|
+
d83172d Auto update addressable to version 2.2.6 (17 hours ago) <Hudson>
|
48
|
+
7dc3b72 Auto update fastercsv to version 1.5.4 (18 hours ago) <Hudson>
|
49
|
+
08ae945 Auto update compass to version 0.11.5 (19 hours ago) <Philippe Creux>
|
50
|
+
fe17166 Auto update hoptoad_notifier to version 2.4.11 (20 hours ago) <Philippe Creux>
|
51
|
+
5875d1a Auto update hoptoad_notifier to version 2.3.12 (21 hours ago) <Philippe Creux>
|
52
|
+
4388e07 Auto update activeadmin to version 0.3.2 (21 hours ago) <Philippe Creux>
|
53
|
+
4cd1d0e Auto update haml to version 3.1.3 (22 hours ago) <Philippe Creux>
|
54
|
+
</pre>
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
MIT
|
59
|
+
|
60
|
+
## Copyright
|
61
|
+
|
62
|
+
Copyright (c) 2011 VersaPay, Philippe Creux.
|
63
|
+
|
@@ -20,14 +20,20 @@ Feature: Auto update Gemfile
|
|
20
20
|
When I run `bundle-auto-update`
|
21
21
|
Then the output should contain:
|
22
22
|
"""
|
23
|
-
Updating dmg
|
23
|
+
Updating dmg
|
24
24
|
- Updating to patch version 0.0.4
|
25
25
|
"""
|
26
26
|
Then the output should contain:
|
27
27
|
"""
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
- Running test suite
|
29
|
+
> rake
|
30
|
+
"""
|
31
|
+
|
32
|
+
Then the output should contain:
|
33
|
+
"""
|
34
|
+
- Test suite failed to run.
|
35
|
+
- Reverting changes
|
36
|
+
> git checkout Gemfile Gemfile.lock
|
31
37
|
"""
|
32
38
|
|
33
39
|
Scenario: Auto Update with custom command
|
@@ -38,15 +44,17 @@ Feature: Auto update Gemfile
|
|
38
44
|
When I run `bundle-auto-update -c echo Hello`
|
39
45
|
Then the output should contain:
|
40
46
|
"""
|
41
|
-
Updating dmg
|
47
|
+
Updating dmg
|
42
48
|
- Updating to patch version 0.0.4
|
43
49
|
"""
|
44
50
|
Then the output should contain:
|
45
51
|
"""
|
46
|
-
|
52
|
+
- Running test suite
|
53
|
+
> echo Hello
|
47
54
|
Hello
|
48
|
-
- Test suite ran successfully.
|
49
|
-
|
55
|
+
- Test suite ran successfully.
|
56
|
+
- Committing changes
|
57
|
+
> git commit Gemfile Gemfile.lock -m 'Auto update dmg to version 0.0.4'
|
50
58
|
"""
|
51
59
|
When I run `git log`
|
52
60
|
Then the output should contain "Auto update dmg to version 0.0.4"
|
data/lib/bundler_auto_update.rb
CHANGED
@@ -47,34 +47,49 @@ module Bundler
|
|
47
47
|
|
48
48
|
def auto_update
|
49
49
|
if updatable?
|
50
|
-
Logger.log "Updating #{gem.name}
|
50
|
+
Logger.log "Updating #{gem.name}"
|
51
51
|
update(:patch) and update(:minor) and update(:major)
|
52
52
|
else
|
53
53
|
Logger.log "#{gem.name} is not auto-updatable, passing it."
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
# @return [Boolean] true on success or when already at latest version
|
57
58
|
def update(version_type)
|
58
59
|
new_version = gem.last_version(version_type)
|
59
60
|
|
60
61
|
if new_version == gem.version
|
61
62
|
Logger.log_indent "Current gem already at latest #{version_type} version. Passing this update."
|
62
|
-
|
63
|
+
|
64
|
+
return true
|
63
65
|
end
|
64
66
|
|
65
67
|
Logger.log_indent "Updating to #{version_type} version #{new_version}"
|
66
68
|
|
67
69
|
gem.version = new_version
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
commit_new_version
|
71
|
+
(update_gemfile and run_test_suite and commit_new_version) or revert_to_previous_version
|
72
|
+
end
|
72
73
|
|
74
|
+
private
|
75
|
+
|
76
|
+
def update_gemfile
|
77
|
+
if gemfile.update_gem(gem)
|
78
|
+
Logger.log_indent "Gemfile updated successfully."
|
73
79
|
true
|
74
80
|
else
|
75
|
-
Logger.log_indent "
|
76
|
-
|
81
|
+
Logger.log_indent "Failed to update Gemfile."
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
77
85
|
|
86
|
+
def run_test_suite
|
87
|
+
Logger.log_indent "Running test suite"
|
88
|
+
if CommandRunner.system test_command
|
89
|
+
Logger.log_indent "Test suite ran successfully."
|
90
|
+
true
|
91
|
+
else
|
92
|
+
Logger.log_indent "Test suite failed to run."
|
78
93
|
false
|
79
94
|
end
|
80
95
|
end
|
@@ -84,21 +99,15 @@ module Bundler
|
|
84
99
|
end
|
85
100
|
|
86
101
|
def commit_new_version
|
87
|
-
|
102
|
+
Logger.log_indent "Committing changes"
|
103
|
+
CommandRunner.system "git commit Gemfile Gemfile.lock -m 'Auto update #{gem.name} to version #{gem.version}'"
|
88
104
|
end
|
89
105
|
|
90
106
|
def revert_to_previous_version
|
91
|
-
|
107
|
+
Logger.log_indent "Reverting changes"
|
108
|
+
CommandRunner.system "git checkout Gemfile Gemfile.lock"
|
92
109
|
gemfile.reload!
|
93
110
|
end
|
94
|
-
|
95
|
-
def run_test_suite
|
96
|
-
run_cmd test_command
|
97
|
-
end
|
98
|
-
|
99
|
-
def run_cmd(cmd)
|
100
|
-
CommandRunner.system(cmd)
|
101
|
-
end
|
102
111
|
end # class Updater
|
103
112
|
|
104
113
|
class Gemfile
|
@@ -172,6 +181,10 @@ module Bundler
|
|
172
181
|
def self.log_indent(msg)
|
173
182
|
log(msg, " - ")
|
174
183
|
end
|
184
|
+
|
185
|
+
def self.log_cmd(msg)
|
186
|
+
log(msg, " > ")
|
187
|
+
end
|
175
188
|
end
|
176
189
|
|
177
190
|
class Dependency
|
@@ -207,13 +220,12 @@ module Bundler
|
|
207
220
|
|
208
221
|
class CommandRunner
|
209
222
|
def self.system(cmd)
|
210
|
-
Logger.
|
223
|
+
Logger.log_cmd cmd
|
224
|
+
|
211
225
|
Kernel.system cmd
|
212
226
|
end
|
213
227
|
|
214
228
|
def self.run(cmd)
|
215
|
-
Logger.log cmd
|
216
|
-
|
217
229
|
`#{cmd}`
|
218
230
|
end
|
219
231
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,23 @@ include Bundler::AutoUpdate
|
|
6
6
|
class Bundler::AutoUpdate::CommandRunner
|
7
7
|
def self.system(cmd)
|
8
8
|
puts "Stub! #{cmd}"
|
9
|
+
|
10
|
+
true
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.run(cmd)
|
12
14
|
puts "Stub! #{cmd}"
|
13
15
|
end
|
14
16
|
end
|
17
|
+
|
18
|
+
class Gemfile
|
19
|
+
def read
|
20
|
+
puts "Stub! read"
|
21
|
+
end
|
22
|
+
|
23
|
+
def write
|
24
|
+
puts "Stub! write"
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
@@ -36,7 +36,7 @@ describe GemUpdater do
|
|
36
36
|
context "when no new version" do
|
37
37
|
it "should return" do
|
38
38
|
gem.should_receive(:last_version).with(:patch) { gem.version }
|
39
|
-
gem_updater.
|
39
|
+
gem_updater.should_not_receive :update_gemfile
|
40
40
|
gem_updater.should_not_receive :run_test_suite
|
41
41
|
|
42
42
|
gem_updater.update(:patch)
|
@@ -47,9 +47,10 @@ describe GemUpdater do
|
|
47
47
|
context "when tests pass" do
|
48
48
|
it "should commit new version" do
|
49
49
|
gem.should_receive(:last_version).with(:patch) { gem.version.next }
|
50
|
-
gem_updater.
|
50
|
+
gem_updater.should_receive(:update_gemfile).and_return true
|
51
51
|
gem_updater.should_receive(:run_test_suite).and_return true
|
52
|
-
gem_updater.should_receive(:commit_new_version)
|
52
|
+
gem_updater.should_receive(:commit_new_version).and_return true
|
53
|
+
gem_updater.should_not_receive(:revert_to_previous_version)
|
53
54
|
|
54
55
|
gem_updater.update(:patch)
|
55
56
|
end
|
@@ -58,9 +59,22 @@ describe GemUpdater do
|
|
58
59
|
context "when tests do not pass" do
|
59
60
|
it "should revert to previous version" do
|
60
61
|
gem.should_receive(:last_version).with(:patch) { gem.version.next }
|
61
|
-
gem_updater.
|
62
|
+
gem_updater.should_receive(:update_gemfile).and_return true
|
62
63
|
gem_updater.should_receive(:run_test_suite).and_return false
|
63
64
|
gem_updater.should_not_receive(:commit_new_version)
|
65
|
+
gem_updater.should_receive(:revert_to_previous_version)
|
66
|
+
|
67
|
+
gem_updater.update(:patch)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when it fails to upgrade gem" do
|
72
|
+
it "should revert to previous version" do
|
73
|
+
gem.should_receive(:last_version).with(:patch) { gem.version.next }
|
74
|
+
gem_updater.should_receive(:update_gemfile).and_return false
|
75
|
+
gem_updater.should_not_receive(:run_test_suite)
|
76
|
+
gem_updater.should_not_receive(:commit_new_version)
|
77
|
+
gem_updater.should_receive(:revert_to_previous_version)
|
64
78
|
|
65
79
|
gem_updater.update(:patch)
|
66
80
|
end
|
data/spec/unit/gemfile_spec.rb
CHANGED
@@ -58,6 +58,7 @@ EOF
|
|
58
58
|
describe "#update_gem" do
|
59
59
|
it "should update the gem version in the Gemfile" do
|
60
60
|
gemfile.update_gem(Dependency.new('rails', '3.1.0'))
|
61
|
+
|
61
62
|
gemfile.content.should include(%{gem 'rails', "3.1.0"})
|
62
63
|
end
|
63
64
|
|
@@ -68,9 +69,17 @@ EOF
|
|
68
69
|
end
|
69
70
|
|
70
71
|
it "should run 'bundle install' against the gem" do
|
71
|
-
CommandRunner.should_receive(:system).with("bundle install")
|
72
|
+
CommandRunner.should_receive(:system).with("bundle install") { true }
|
73
|
+
CommandRunner.should_not_receive(:system).with("bundle update rails")
|
72
74
|
|
73
75
|
gemfile.update_gem(Dependency.new('rails', '3.1.0'))
|
74
76
|
end
|
77
|
+
|
78
|
+
it "should run 'bundle update' against the gem when bundle install fails because a gem version is locked" do
|
79
|
+
CommandRunner.should_receive(:system).with("bundle install").and_return false
|
80
|
+
CommandRunner.should_receive(:system).with("bundle update rails").and_return true
|
81
|
+
|
82
|
+
gemfile.update_gem(Dependency.new('rails', '3.1.0')).should == true
|
83
|
+
end
|
75
84
|
end
|
76
85
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundler-auto-update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philippe Creux
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-06 00:00:00 +02:00
|
19
19
|
default_executable: bundle-auto-update
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- .gitignore
|
76
76
|
- Gemfile
|
77
|
+
- README.md
|
77
78
|
- Rakefile
|
78
79
|
- bin/bundle-auto-update
|
79
80
|
- bundler-auto-update.gemspec
|