bump 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/bin/bump +3 -1
- data/bump.gemspec +1 -1
- data/lib/bump.rb +39 -45
- data/spec/bump_spec.rb +87 -31
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/bin/bump
CHANGED
data/bump.gemspec
CHANGED
data/lib/bump.rb
CHANGED
@@ -7,61 +7,53 @@ module Bump
|
|
7
7
|
|
8
8
|
class Bump
|
9
9
|
|
10
|
-
attr_accessor :bump, :
|
10
|
+
attr_accessor :bump, :gemspec_path, :version, :next_version
|
11
11
|
|
12
12
|
BUMPS = %w(major minor tiny)
|
13
13
|
OPTIONS = BUMPS | ["current"]
|
14
|
-
VERSION_REGEX =
|
14
|
+
VERSION_REGEX = /\.version\s*=\s*["'](\d+\.\d+\.\d+)["']/
|
15
15
|
|
16
16
|
def initialize(bump)
|
17
17
|
@bump = bump.is_a?(Array) ? bump.first : bump
|
18
18
|
end
|
19
19
|
|
20
20
|
def run
|
21
|
-
|
22
|
-
raise InvalidOptionError unless OPTIONS.include?(@bump)
|
21
|
+
@version = find_current_version
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
current
|
32
|
-
else
|
33
|
-
raise Exception
|
34
|
-
end
|
35
|
-
|
36
|
-
rescue InvalidOptionError
|
37
|
-
@output = "Invalid option. Choose between #{OPTIONS.join(',')}."
|
38
|
-
rescue UnfoundVersionError
|
39
|
-
@output = "Unable to find your gem version"
|
40
|
-
rescue UnfoundGemspecError
|
41
|
-
@output = "Unable to find gemspec file"
|
42
|
-
rescue TooManyGemspecsFoundError
|
43
|
-
@output = "More than one gemspec file"
|
44
|
-
rescue Exception => e
|
45
|
-
@output = "Something wrong happened: #{e.message}"
|
23
|
+
case @bump
|
24
|
+
when "major", "minor", "tiny"
|
25
|
+
bump
|
26
|
+
when "current"
|
27
|
+
current
|
28
|
+
else
|
29
|
+
raise InvalidOptionError
|
46
30
|
end
|
47
|
-
|
48
|
-
|
31
|
+
rescue InvalidOptionError
|
32
|
+
["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
|
33
|
+
rescue UnfoundVersionError
|
34
|
+
["Unable to find your gem version", 1]
|
35
|
+
rescue UnfoundGemspecError
|
36
|
+
["Unable to find gemspec file", 1]
|
37
|
+
rescue TooManyGemspecsFoundError
|
38
|
+
["More than one gemspec file", 1]
|
39
|
+
rescue Exception => e
|
40
|
+
["Something wrong happened: #{e.message}", 1]
|
49
41
|
end
|
50
42
|
|
51
43
|
private
|
52
44
|
|
53
45
|
def bump
|
54
46
|
@next_version = find_next_version
|
55
|
-
system(%(ruby -i -pe "gsub(/#{@version}/, '#{@next_version}')" #{
|
56
|
-
|
47
|
+
system(%(ruby -i -pe "gsub(/#{@version}/, '#{@next_version}')" #{gemspec_path}))
|
48
|
+
["Bump version #{@version} to #{@next_version}", 0]
|
57
49
|
end
|
58
50
|
|
59
51
|
def current
|
60
|
-
|
52
|
+
["Current version: #{@version}", 0]
|
61
53
|
end
|
62
54
|
|
63
55
|
def find_current_version
|
64
|
-
match = File.read(
|
56
|
+
match = File.read(gemspec_path).match VERSION_REGEX
|
65
57
|
if match.nil?
|
66
58
|
raise UnfoundVersionError
|
67
59
|
else
|
@@ -69,24 +61,26 @@ module Bump
|
|
69
61
|
end
|
70
62
|
end
|
71
63
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
def gemspec_path
|
65
|
+
@gemspec_path ||= begin
|
66
|
+
gemspecs = Dir.glob("*.gemspec")
|
67
|
+
raise UnfoundGemspecError if gemspecs.size.zero?
|
68
|
+
raise TooManyGemspecsFoundError if gemspecs.size > 1
|
69
|
+
gemspecs.first
|
70
|
+
end
|
77
71
|
end
|
78
72
|
|
79
73
|
def find_next_version
|
80
|
-
match = @version.match /(\d)
|
74
|
+
match = @version.match /(\d+)\.(\d+)\.(\d+)/
|
81
75
|
case @bump
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
when "major"
|
77
|
+
"#{match[1].to_i + 1}.0.0"
|
78
|
+
when "minor"
|
79
|
+
"#{match[1]}.#{match[2].to_i + 1}.0"
|
80
|
+
when "tiny"
|
81
|
+
"#{match[1]}.#{match[2]}.#{match[3].to_i + 1}"
|
88
82
|
end
|
89
|
-
end
|
83
|
+
end
|
90
84
|
|
91
85
|
end
|
92
86
|
end
|
data/spec/bump_spec.rb
CHANGED
@@ -1,45 +1,101 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../lib/bump.rb"
|
2
2
|
|
3
3
|
describe Bump do
|
4
|
+
let(:gemspec){ "fixture.gemspec" }
|
4
5
|
|
5
6
|
around do |example|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
path = File.expand_path("../fixture/fixture.gemspec", __FILE__)
|
12
|
-
File.open(path, 'w') {|f| f.write(gemspec) }
|
13
|
-
example.call
|
14
|
-
File.open(path, 'w') {|f| f.write("") }
|
7
|
+
run "rm -rf fixture && mkdir fixture"
|
8
|
+
Dir.chdir "fixture" do
|
9
|
+
example.call
|
10
|
+
end
|
11
|
+
run "rm -rf fixture"
|
15
12
|
end
|
16
13
|
|
17
|
-
it "should find
|
18
|
-
bump
|
19
|
-
bump.gemspec_path = File.dirname(__FILE__) + "/fixture/fixture.gemspec"
|
20
|
-
output = bump.run
|
21
|
-
output.include?("1.0.0").should be_true
|
14
|
+
it "should fail if it cannot find anything to bump" do
|
15
|
+
bump("current", :fail => true).should include "Unable to find"
|
22
16
|
end
|
23
17
|
|
24
|
-
it "should
|
25
|
-
|
26
|
-
bump
|
27
|
-
output = bump.run
|
28
|
-
output.include?("1.0.1").should be_true
|
18
|
+
it "should fail without command" do
|
19
|
+
write_gemspec
|
20
|
+
bump("", :fail => true).should include "Invalid option"
|
29
21
|
end
|
30
|
-
|
31
|
-
it "should
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
output.include?("1.1.0").should be_true
|
22
|
+
|
23
|
+
it "should fail with multiple gemspecs" do
|
24
|
+
write_gemspec
|
25
|
+
write("xxxx.gemspec", "xxx")
|
26
|
+
bump("", :fail => true).should include "More than one gemspec file"
|
36
27
|
end
|
37
|
-
|
38
|
-
it "should
|
39
|
-
|
40
|
-
bump
|
41
|
-
output = bump.run
|
42
|
-
output.include?("2.0.0").should be_true
|
28
|
+
|
29
|
+
it "should fail if version is weird" do
|
30
|
+
write_gemspec("a.b.c")
|
31
|
+
bump("", :fail => true).should include "Unable to find your gem version"
|
43
32
|
end
|
44
33
|
|
34
|
+
context ".version in gemspect" do
|
35
|
+
before do
|
36
|
+
write_gemspec
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should find current version" do
|
40
|
+
bump("current").should include("4.2.3")
|
41
|
+
read(gemspec).should include('s.version = "4.2.3"')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should bump tiny" do
|
45
|
+
bump("tiny").should include("4.2.4")
|
46
|
+
read(gemspec).should include('s.version = "4.2.4"')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should bump minor" do
|
50
|
+
bump("minor").should include("4.3.0")
|
51
|
+
read(gemspec).should include('s.version = "4.3.0"')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should bump major" do
|
55
|
+
bump("major").should include("5.0.0")
|
56
|
+
read(gemspec).should include('s.version = "5.0.0"')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should bump more then 10" do
|
60
|
+
bump("tiny").should include("4.2.4")
|
61
|
+
bump("tiny").should include("4.2.5")
|
62
|
+
bump("tiny").should include("4.2.6")
|
63
|
+
bump("tiny").should include("4.2.7")
|
64
|
+
bump("tiny").should include("4.2.8")
|
65
|
+
bump("tiny").should include("4.2.9")
|
66
|
+
bump("tiny").should include("4.2.10")
|
67
|
+
bump("tiny").should include("4.2.11")
|
68
|
+
read(gemspec).should include('s.version = "4.2.11"')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def write(file, content)
|
75
|
+
folder = File.dirname(file)
|
76
|
+
run "mkdir -p #{folder}" unless File.exist?(folder)
|
77
|
+
File.open(file, 'w'){|f| f.write content }
|
78
|
+
end
|
79
|
+
|
80
|
+
def read(file)
|
81
|
+
File.read(file)
|
82
|
+
end
|
83
|
+
|
84
|
+
def run(cmd, options={})
|
85
|
+
result = `#{cmd} 2>&1`
|
86
|
+
raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
def bump(command="", options={})
|
91
|
+
run "#{File.expand_path("../../bin/bump", __FILE__)} #{command}", options
|
92
|
+
end
|
93
|
+
|
94
|
+
def write_gemspec(version = "4.2.3")
|
95
|
+
write gemspec, <<-RUBY.sub(" "*6, "")
|
96
|
+
Gem::Specification.new do |s|
|
97
|
+
s.version = "#{version}"
|
98
|
+
end
|
99
|
+
RUBY
|
100
|
+
end
|
45
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: g.marcilhacy@gmail.com
|