bmp 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bmp.yml +3 -3
- data/.editorconfig +1 -2
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +15 -1
- data/README.md +42 -3
- data/Rakefile +5 -3
- data/TODO.md +9 -11
- data/bin/bmp +13 -1
- data/bump.gemspec +12 -13
- data/lib/bump.rb +0 -1
- data/lib/bump/application.rb +228 -217
- data/lib/bump/cli.rb +14 -34
- data/lib/bump/command.rb +12 -18
- data/lib/bump/domain.rb +0 -2
- data/lib/bump/domain/bump_info.rb +61 -120
- data/lib/bump/domain/bump_info_repository.rb +32 -42
- data/lib/bump/domain/file_update_rule.rb +41 -68
- data/lib/bump/domain/file_update_rule_factory.rb +19 -27
- data/lib/bump/domain/version_number.rb +39 -56
- data/lib/bump/domain/version_number_factory.rb +14 -20
- data/lib/bump/logger.rb +40 -46
- data/lib/bump/version.rb +1 -2
- data/spec/bump/application_spec.rb +119 -36
- data/spec/bump/cli_spec.rb +8 -1
- data/spec/bump/command_spec.rb +10 -17
- data/spec/bump/domain/bump_info_repository_spec.rb +17 -24
- data/spec/bump/domain/bump_info_spec.rb +50 -26
- data/spec/bump/domain/file_update_rule_factory_spec.rb +16 -26
- data/spec/bump/domain/file_update_rule_spec.rb +23 -33
- data/spec/bump/domain/version_number_factory_spec.rb +8 -31
- data/spec/bump/domain/version_number_spec.rb +46 -98
- data/spec/bump/logger_spec.rb +29 -1
- data/spec/fixture/bmp.yml +1 -1
- data/spec/fixture/bmp_invalid.yml +5 -0
- data/spec/fixture/bmp_invalid_pattern.yml +3 -0
- data/spec/fixture/bmp_tmp.yml +5 -0
- data/spec/spec_helper.rb +1 -4
- metadata +9 -2
@@ -1,30 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Bump
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
return FileUpdateRule.new file, nil, before_version, after_version
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
2
|
+
# The factory class for the file update rule model
|
3
|
+
class FileUpdateRuleFactory
|
4
|
+
# Creates the file update rule from the given params.
|
5
|
+
#
|
6
|
+
# @param [String] file The filename
|
7
|
+
# @param [String|Array] param The version update info
|
8
|
+
# @param [String] before_version
|
9
|
+
# @param [String] after_version
|
10
|
+
# @return [Bump::FileUpdateRule, Array<Bump::FileUpdateRule>]
|
11
|
+
def self.create(file, param, before_version, after_version)
|
12
|
+
case param
|
13
|
+
when String
|
14
|
+
return FileUpdateRule.new file, param, before_version, after_version
|
15
|
+
when Array
|
16
|
+
return param.map { |param0| FileUpdateRule.new file, param0, before_version, after_version }.flatten
|
17
|
+
else
|
18
|
+
return FileUpdateRule.new file, nil, before_version, after_version
|
19
|
+
end
|
28
20
|
end
|
29
|
-
|
21
|
+
end
|
30
22
|
end
|
@@ -1,63 +1,46 @@
|
|
1
|
-
# lib/bump/domain/version.rb
|
2
|
-
|
3
1
|
module Bump
|
2
|
+
# The version number model
|
3
|
+
class VersionNumber
|
4
|
+
attr_writer :preid
|
5
|
+
|
6
|
+
# @param [Integer] major
|
7
|
+
# @param [Integer] minor
|
8
|
+
# @param [Integer] patch
|
9
|
+
# @param [String, nil] preid
|
10
|
+
def initialize(major, minor, patch, preid = nil)
|
11
|
+
@major = major
|
12
|
+
@minor = minor
|
13
|
+
@patch = patch
|
14
|
+
@preid = preid
|
15
|
+
end
|
4
16
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def bump level
|
24
|
-
|
25
|
-
case level
|
26
|
-
when :major
|
27
|
-
@major += 1
|
28
|
-
@minor = 0
|
29
|
-
@patch = 0
|
30
|
-
when :minor
|
31
|
-
@minor += 1
|
32
|
-
@patch = 0
|
33
|
-
when :patch
|
34
|
-
@patch += 1
|
35
|
-
end
|
36
|
-
@preid = nil
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
# Sets the preid
|
41
|
-
#
|
42
|
-
# @return [void]
|
43
|
-
def setPreid preid
|
44
|
-
@preid = preid
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns the string representation of the version
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
def to_s
|
51
|
-
label = @major.to_s + '.' + @minor.to_s + '.' + @patch.to_s
|
52
|
-
|
53
|
-
if @preid
|
54
|
-
label = label + '-' + @preid
|
55
|
-
end
|
17
|
+
# Bumps the version at the given level
|
18
|
+
#
|
19
|
+
# @param [Symbol] level
|
20
|
+
# @return [void]
|
21
|
+
def bump(level)
|
22
|
+
case level
|
23
|
+
when :major
|
24
|
+
@major += 1
|
25
|
+
@minor = 0
|
26
|
+
@patch = 0
|
27
|
+
when :minor
|
28
|
+
@minor += 1
|
29
|
+
@patch = 0
|
30
|
+
when :patch
|
31
|
+
@patch += 1
|
32
|
+
end
|
33
|
+
@preid = nil
|
34
|
+
end
|
56
35
|
|
57
|
-
|
36
|
+
# Returns the string representation of the version
|
37
|
+
# @return [String]
|
38
|
+
def to_s
|
39
|
+
label = @major.to_s + '.' + @minor.to_s + '.' + @patch.to_s
|
58
40
|
|
59
|
-
|
41
|
+
label = label + '-' + @preid if @preid
|
60
42
|
|
43
|
+
label
|
61
44
|
end
|
62
|
-
|
45
|
+
end
|
63
46
|
end
|
@@ -1,23 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Bump
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
return VersionNumber.new match[1].to_i, match[2].to_i, match[3].to_i, match[5]
|
19
|
-
end
|
20
|
-
|
2
|
+
# The factory class for the version number
|
3
|
+
class VersionNumberFactory
|
4
|
+
# Regexp for version expression
|
5
|
+
VERSION_REGEXP = /^(\d+).(\d+).(\d+)(-(\S*))?$/
|
6
|
+
|
7
|
+
# Creates the version number object from the string
|
8
|
+
#
|
9
|
+
# @param [String] version_string
|
10
|
+
# @return [Bump::VersionNumber]
|
11
|
+
def self.from_string(version_string)
|
12
|
+
match = VERSION_REGEXP.match version_string
|
13
|
+
|
14
|
+
VersionNumber.new match[1].to_i, match[2].to_i, match[3].to_i, match[5]
|
21
15
|
end
|
22
|
-
|
16
|
+
end
|
23
17
|
end
|
data/lib/bump/logger.rb
CHANGED
@@ -1,54 +1,48 @@
|
|
1
|
-
# lib/bump/logger.rb
|
2
|
-
|
3
1
|
module Bump
|
2
|
+
# The logging class
|
3
|
+
class Logger
|
4
|
+
def initialize(no_color = nil)
|
5
|
+
@no_color = no_color
|
6
|
+
end
|
4
7
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# @param [String] message
|
13
|
-
# @param [Boolean] breakline
|
14
|
-
# @return [void]
|
15
|
-
def log message = '', breakline = true
|
16
|
-
print message
|
17
|
-
|
18
|
-
if breakline
|
19
|
-
print "\n"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Colorize the text by the color code.
|
24
|
-
#
|
25
|
-
# @param [String] text
|
26
|
-
# @param [Integer] color_code
|
27
|
-
# @return [String]
|
28
|
-
def colorize text, color_code
|
29
|
-
if @no_color
|
30
|
-
text
|
31
|
-
else
|
32
|
-
"\e[#{color_code}m#{text}\e[0m"
|
33
|
-
end
|
34
|
-
end
|
8
|
+
# Logs the message.
|
9
|
+
#
|
10
|
+
# @param [String] message
|
11
|
+
# @param [Boolean] breakline
|
12
|
+
# @return [void]
|
13
|
+
def log(message = '', breakline = true)
|
14
|
+
print message
|
35
15
|
|
36
|
-
|
37
|
-
|
38
|
-
# @param [String] text
|
39
|
-
# @return [String]
|
40
|
-
def green text
|
41
|
-
colorize text, 32
|
42
|
-
end
|
16
|
+
print "\n" if breakline
|
17
|
+
end
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
19
|
+
# Colorize the text by the color code.
|
20
|
+
#
|
21
|
+
# @param [String] text
|
22
|
+
# @param [Integer] color_code
|
23
|
+
# @return [String]
|
24
|
+
def colorize(text, color_code)
|
25
|
+
if @no_color
|
26
|
+
text
|
27
|
+
else
|
28
|
+
"\e[#{color_code}m#{text}\e[0m"
|
29
|
+
end
|
30
|
+
end
|
51
31
|
|
32
|
+
# Returns a green string.
|
33
|
+
#
|
34
|
+
# @param [String] text
|
35
|
+
# @return [String]
|
36
|
+
def green(text)
|
37
|
+
colorize text, 32
|
52
38
|
end
|
53
39
|
|
40
|
+
# Returns a red string.
|
41
|
+
#
|
42
|
+
# @param [String] text
|
43
|
+
# @return [String]
|
44
|
+
def red(text)
|
45
|
+
colorize text, 31
|
46
|
+
end
|
47
|
+
end
|
54
48
|
end
|
data/lib/bump/version.rb
CHANGED
@@ -3,70 +3,153 @@ require 'spec_helper'
|
|
3
3
|
require 'bump'
|
4
4
|
|
5
5
|
describe Bump::Application do
|
6
|
+
before :each do
|
7
|
+
@help_message = 'help_message'
|
8
|
+
@version_exp = "Bmp #{Bump::VERSION}"
|
9
|
+
@bmp_file = 'spec/fixture/bmp.yml'
|
10
|
+
|
11
|
+
@logger = double 'logger'
|
12
|
+
allow(@logger).to receive(:log)
|
13
|
+
allow(@logger).to receive(:green)
|
14
|
+
allow(@logger).to receive(:red)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#select_action' do
|
18
|
+
it 'returns :help if the options contain :help' do
|
19
|
+
app = Bump::Application.new({ help: true }, @help_message, @version_exp, @bmp_file, @logger)
|
20
|
+
|
21
|
+
expect(app.select_action).to eq :help
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns :version if the :version option preset' do
|
25
|
+
app = Bump::Application.new({ version: true }, @help_message, @version_exp, @bmp_file, @logger)
|
26
|
+
|
27
|
+
expect(app.select_action).to eq :version
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns :info if the :info option present' do
|
31
|
+
app = Bump::Application.new({ info: true }, @help_message, @version_exp, @bmp_file, @logger)
|
32
|
+
|
33
|
+
expect(app.select_action).to eq :info
|
34
|
+
end
|
6
35
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
36
|
+
it 'returns :bump if one of :major, :minor, :patch, :commit, :preid, :release options present' do
|
37
|
+
app = Bump::Application.new({ major: true }, @help_message, @version_exp, @bmp_file, @logger)
|
38
|
+
expect(app.select_action).to eq :bump
|
39
|
+
|
40
|
+
app = Bump::Application.new({ minor: true }, @help_message, @version_exp, @bmp_file, @logger)
|
41
|
+
expect(app.select_action).to eq :bump
|
42
|
+
|
43
|
+
app = Bump::Application.new({ patch: true }, @help_message, @version_exp, @bmp_file, @logger)
|
44
|
+
expect(app.select_action).to eq :bump
|
45
|
+
|
46
|
+
app = Bump::Application.new({ commit: true }, @help_message, @version_exp, @bmp_file, @logger)
|
47
|
+
expect(app.select_action).to eq :bump
|
48
|
+
|
49
|
+
app = Bump::Application.new({ preid: true }, @help_message, @version_exp, @bmp_file, @logger)
|
50
|
+
expect(app.select_action).to eq :bump
|
51
|
+
|
52
|
+
app = Bump::Application.new({ release: true }, @help_message, @version_exp, @bmp_file, @logger)
|
53
|
+
expect(app.select_action).to eq :bump
|
54
|
+
end
|
12
55
|
|
56
|
+
it 'returns :info if none of the above options are present' do
|
57
|
+
app = Bump::Application.new({}, @help_message, @version_exp, @bmp_file, @logger)
|
58
|
+
expect(app.select_action).to eq :info
|
13
59
|
end
|
60
|
+
end
|
14
61
|
|
15
|
-
|
62
|
+
describe '#main' do
|
63
|
+
it 'logs version and returns true when the version option is given' do
|
64
|
+
expect(@logger).to receive(:log).with("Bmp #{Bump::VERSION}", true).once
|
16
65
|
|
17
|
-
|
66
|
+
app = Bump::Application.new({ version: true }, @help_message, @version_exp, @bmp_file, @logger)
|
67
|
+
expect(app.main).to be true
|
68
|
+
end
|
18
69
|
|
19
|
-
|
70
|
+
it 'logs help message and returns true when the help option is given' do
|
71
|
+
expect(@logger).to receive(:log).with('help_message', true).once
|
20
72
|
|
21
|
-
|
73
|
+
app = Bump::Application.new({ help: true }, @help_message, @version_exp, @bmp_file, @logger)
|
74
|
+
expect(app.main).to be true
|
75
|
+
end
|
22
76
|
|
23
|
-
|
77
|
+
it 'shows bump info and return true when there is no error' do
|
78
|
+
app = Bump::Application.new({ info: true }, @help_message, @version_exp, @bmp_file, @logger)
|
24
79
|
|
25
|
-
|
80
|
+
expect(app.main).to be true
|
81
|
+
end
|
26
82
|
|
27
|
-
|
83
|
+
it 'shows bump info and returns false when there are errors' do
|
84
|
+
app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid.yml', @logger)
|
28
85
|
|
29
|
-
|
86
|
+
expect(app.main).to be false
|
87
|
+
end
|
30
88
|
|
31
|
-
|
89
|
+
it 'returns false when the pattern in bmp.yml is invalid' do
|
90
|
+
app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
32
91
|
|
33
|
-
|
92
|
+
expect(app.main).to be false
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns false when the bmp.yml not found' do
|
96
|
+
app = Bump::Application.new({ info: true }, @help_message, @version_exp, 'spec/fixture/bmp_not_exists.yml', @logger)
|
34
97
|
|
35
|
-
|
98
|
+
expect(app.main).to be false
|
99
|
+
end
|
36
100
|
|
37
|
-
|
101
|
+
describe 'with :major|:minor|:patch|:preid|:release options' do
|
102
|
+
it 'returns false when the pattern in bmp.yml is invalid' do
|
103
|
+
app = Bump::Application.new({ major: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
38
104
|
|
39
|
-
|
105
|
+
expect(app.main).to be false
|
40
106
|
|
41
|
-
|
107
|
+
app = Bump::Application.new({ minor: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
42
108
|
|
43
|
-
|
44
|
-
expect(app.selectAction).to eq :bump
|
109
|
+
expect(app.main).to be false
|
45
110
|
|
46
|
-
|
47
|
-
expect(app.selectAction).to eq :bump
|
111
|
+
app = Bump::Application.new({ patch: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
48
112
|
|
49
|
-
|
50
|
-
expect(app.selectAction).to eq :bump
|
113
|
+
expect(app.main).to be false
|
51
114
|
|
52
|
-
|
53
|
-
expect(app.selectAction).to eq :bump
|
115
|
+
app = Bump::Application.new({ preid: 'beta.1' }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
54
116
|
|
55
|
-
|
56
|
-
expect(app.selectAction).to eq :bump
|
117
|
+
expect(app.main).to be false
|
57
118
|
|
58
|
-
|
59
|
-
expect(app.selectAction).to eq :bump
|
119
|
+
app = Bump::Application.new({ release: true }, @help_message, @version_exp, 'spec/fixture/bmp_invalid_pattern.yml', @logger)
|
60
120
|
|
61
|
-
|
121
|
+
expect(app.main).to be false
|
122
|
+
end
|
62
123
|
|
63
|
-
|
124
|
+
it 'returns true when no error found' do
|
125
|
+
File.write 'spec/fixture/tmp_bmp_tmp.yml', File.read('spec/fixture/bmp_tmp.yml', encoding: Encoding::UTF_8)
|
126
|
+
File.write 'spec/fixture/tmp_dummy.txt', File.read('spec/fixture/dummy.txt', encoding: Encoding::UTF_8)
|
64
127
|
|
65
|
-
|
66
|
-
expect(app.selectAction).to eq :info
|
128
|
+
app = Bump::Application.new({ patch: true }, @help_message, @version_exp, 'spec/fixture/tmp_bmp_tmp.yml', @logger)
|
67
129
|
|
68
|
-
|
130
|
+
expect(app.main).to be true
|
69
131
|
|
132
|
+
File.delete 'spec/fixture/tmp_bmp_tmp.yml'
|
133
|
+
File.delete 'spec/fixture/tmp_dummy.txt'
|
134
|
+
end
|
70
135
|
end
|
71
136
|
|
137
|
+
describe 'with :commit options' do
|
138
|
+
it 'executes git commands if there is no error' do
|
139
|
+
File.write 'spec/fixture/tmp_bmp_tmp.yml', File.read('spec/fixture/bmp_tmp.yml', encoding: Encoding::UTF_8)
|
140
|
+
File.write 'spec/fixture/tmp_dummy.txt', File.read('spec/fixture/dummy.txt', encoding: Encoding::UTF_8)
|
141
|
+
|
142
|
+
command = double 'command'
|
143
|
+
|
144
|
+
app = Bump::Application.new({ patch: true, commit: true }, @help_message, @version_exp, 'spec/fixture/tmp_bmp_tmp.yml', @logger, command)
|
145
|
+
|
146
|
+
expect(command).to receive(:exec).thrice
|
147
|
+
|
148
|
+
expect(app.main).to be true
|
149
|
+
|
150
|
+
File.delete 'spec/fixture/tmp_bmp_tmp.yml'
|
151
|
+
File.delete 'spec/fixture/tmp_dummy.txt'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
72
155
|
end
|