bump 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -8
  3. data/bin/bump +1 -1
  4. data/lib/bump.rb +152 -145
  5. data/lib/bump/tasks.rb +1 -1
  6. metadata +21 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1175cf2868e448afaf993f17409112483889ed04
4
- data.tar.gz: 29be419ef76fed2ca063e1eea18f6fbc922a019e
3
+ metadata.gz: 3a574d2178ab81ef0b3933c40c61d63f1f186c79
4
+ data.tar.gz: 19ac68b8d7e0be7d29d72bc5c99a02cd64faec64
5
5
  SHA512:
6
- metadata.gz: a31e2f7327abba449c4144807c2f20471a3d67566800fe77326507be5d4d22fc93b2885e67f87f3d9fa9530d8cad6fa0d4e9223d5761efde0894efe31335b2e0
7
- data.tar.gz: ccca570ac125a618f0524664a975838c1e5e3673dfd2e4ccb110300367360f8880c47e8d07fdc0cf422d690f9e9042304716c97b9d53caa2b26b7daee533d303
6
+ metadata.gz: eff95fab4f733f9250d4705200a35f3fd30be85b73aa62b8f4bf0dbc52470073c9d7709d87b0398e9bff70e0bd12b2922e406d200c24c85b4f07c1db81ec4d14
7
+ data.tar.gz: dad1267f7b8c2985b79cafb08e76b6fae46c8d8751715b4dbea552bfb64d685b3aae870d3882d14e49e76fa0fcd7aa56b1dafb9a267087739e82eb8108c40b5f
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.org/gregorym/bump.png)](https://travis-ci.org/gregorym/bump)
2
- [![Gem Version](https://badge.fury.io/rb/bump.png)](http://badge.fury.io/rb/bump)
1
+ [![Build Status](https://travis-ci.org/gregorym/bump.svg)](https://travis-ci.org/gregorym/bump)
2
+ [![Gem Version](https://badge.fury.io/rb/bump.svg)](http://badge.fury.io/rb/bump)
3
3
 
4
4
  # Introduction
5
5
  Bump is a gem that will simplify the way you build gems and chef-cookbooks.
@@ -40,16 +40,26 @@ If you don't want to run the `bundle` command after bumping, add the `--no-bundl
40
40
 
41
41
  bump patch --no-bundle
42
42
 
43
- ### --commit-message [MSG]
44
- If you want to append additional information to the commit message, pass it in using the `--commit-message [MSG]` option.
43
+ ### --commit-message [MSG], -m [MSG]
44
+ If you want to append additional information to the commit message, pass it in using the `--commit-message [MSG]` or `-m [MSG]` option.
45
45
 
46
46
  bump patch --commit-message [no-ci]
47
47
 
48
+ or
49
+
50
+ bump patch -m [no-cli]
51
+
48
52
  ### Rake
49
53
 
50
54
  ```Ruby
51
55
  # Rakefile
52
56
  require "bump/tasks"
57
+
58
+ #
59
+ # if you want to always tag the verison, add:
60
+ # Bump.tag_by_default = true
61
+ #
62
+
53
63
  ```
54
64
 
55
65
  rake bump:patch
@@ -69,10 +79,7 @@ Bump::Bump.run("patch", commit_message: '[no ci]') # -> creates a commit message
69
79
  - gemspec with `gem.version = "1.2.3"` or `Gem:Specification.new "gem-name", "1.2.3" do`
70
80
  - lib/**/version.rb file with `VERSION = "1.2.3"`
71
81
  - metadata.rb with `version "1.2.3"`
72
-
73
- # Todo
74
-
75
- - `VERSION = "1.2.3"` in lib/*.rb
82
+ - `VERSION = "1.2.3"` in lib/**/*.rb
76
83
 
77
84
  # Author
78
85
  Gregory<br/>
data/bin/bump CHANGED
@@ -17,7 +17,7 @@ Usage:
17
17
  Options:
18
18
  BANNER
19
19
  opts.on("--no-commit", "Do not make a commit.") { options[:commit] = false }
20
- opts.on("--commit-message [MSG]", "Append MSG to the commit message.") {|msg| options[:commit_message] = msg }
20
+ opts.on("-m","--commit-message [MSG]", "Append MSG to the commit message.") {|msg| options[:commit_message] = msg }
21
21
  opts.on("--no-bundle", "Do not bundle.") { options[:bundle] = false }
22
22
  opts.on("--tag", "Create git tag from version (only if commit is true).") { options[:tag] = true }
23
23
  opts.on("-h", "--help","Show this.") { puts opts; exit }
@@ -5,184 +5,191 @@ module Bump
5
5
  class TooManyVersionFilesError < StandardError; end
6
6
  class UnfoundVersionFileError < StandardError; end
7
7
 
8
+ class <<self
9
+ attr_accessor :tag_by_default
10
+ end
11
+
8
12
  class Bump
9
13
  BUMPS = %w(major minor patch pre)
10
14
  PRERELEASE = ["alpha","beta","rc",nil]
11
15
  OPTIONS = BUMPS | ["set", "current"]
12
16
  VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/
13
17
 
14
- def self.defaults
15
- {
16
- :commit => true,
17
- :bundle => File.exist?("Gemfile"),
18
- :tag => false
19
- }
20
- end
18
+ class << self
21
19
 
22
- def self.run(bump, options={})
23
- options = defaults.merge(options)
24
-
25
- case bump
26
- when *BUMPS
27
- bump_part(bump, options)
28
- when "set"
29
- raise InvalidVersionError unless options[:version]
30
- bump_set(options[:version], options)
31
- when "current"
32
- ["Current version: #{current}", 0]
33
- else
34
- raise InvalidOptionError
35
- end
36
- rescue InvalidOptionError
37
- ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
38
- rescue InvalidVersionError
39
- ["Invalid version number given.", 1]
40
- rescue UnfoundVersionError
41
- ["Unable to find your gem version", 1]
42
- rescue UnfoundVersionFileError
43
- ["Unable to find a file with the gem version", 1]
44
- rescue TooManyVersionFilesError
45
- ["More than one version file found (#{$!.message})", 1]
46
- end
20
+ def defaults
21
+ {
22
+ :commit => true,
23
+ :bundle => File.exist?("Gemfile"),
24
+ :tag => ::Bump.tag_by_default
25
+ }
26
+ end
47
27
 
48
- def self.current
49
- current_info.first
50
- end
28
+ def run(bump, options={})
29
+ options = defaults.merge(options)
30
+
31
+ case bump
32
+ when *BUMPS
33
+ bump_part(bump, options)
34
+ when "set"
35
+ raise InvalidVersionError unless options[:version]
36
+ bump_set(options[:version], options)
37
+ when "current"
38
+ ["Current version: #{current}", 0]
39
+ else
40
+ raise InvalidOptionError
41
+ end
42
+ rescue InvalidOptionError
43
+ ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
44
+ rescue InvalidVersionError
45
+ ["Invalid version number given.", 1]
46
+ rescue UnfoundVersionError
47
+ ["Unable to find your gem version", 1]
48
+ rescue UnfoundVersionFileError
49
+ ["Unable to find a file with the gem version", 1]
50
+ rescue TooManyVersionFilesError
51
+ ["More than one version file found (#{$!.message})", 1]
52
+ end
51
53
 
52
- private
54
+ def current
55
+ current_info.first
56
+ end
53
57
 
54
- def self.bump(file, current, next_version, options)
55
- replace(file, current, next_version)
56
- if options[:bundle] and under_version_control?("Gemfile.lock")
57
- bundler_with_clean_env do
58
- system("bundle")
58
+ private
59
+
60
+ def bump(file, current, next_version, options)
61
+ replace(file, current, next_version)
62
+ if options[:bundle] and Dir.glob('*.gemspec').any? and under_version_control?("Gemfile.lock")
63
+ bundler_with_clean_env do
64
+ return ["Bundle error", 1] unless system("bundle")
65
+ end
59
66
  end
67
+ commit(next_version, file, options) if options[:commit]
68
+ ["Bump version #{current} to #{next_version}", 0]
60
69
  end
61
- commit(next_version, file, options) if options[:commit]
62
- ["Bump version #{current} to #{next_version}", 0]
63
- end
64
70
 
65
- def self.bundler_with_clean_env(&block)
66
- if defined?(Bundler)
67
- Bundler.with_clean_env(&block)
68
- else
69
- yield
71
+ def bundler_with_clean_env(&block)
72
+ if defined?(Bundler)
73
+ Bundler.with_clean_env(&block)
74
+ else
75
+ yield
76
+ end
70
77
  end
71
- end
72
78
 
73
- def self.bump_part(part, options)
74
- current, file = current_info
75
- next_version = next_version(current, part)
76
- bump(file, current, next_version, options)
77
- end
79
+ def bump_part(part, options)
80
+ current, file = current_info
81
+ next_version = next_version(current, part)
82
+ bump(file, current, next_version, options)
83
+ end
78
84
 
79
- def self.bump_set(next_version, options)
80
- current, file = current_info
81
- bump(file, current, next_version, options)
82
- end
85
+ def bump_set(next_version, options)
86
+ current, file = current_info
87
+ bump(file, current, next_version, options)
88
+ end
83
89
 
84
- def self.commit_message(version, options)
85
- (options[:commit_message]) ? "v#{version} #{options[:commit_message]}" : "v#{version}"
86
- end
90
+ def commit_message(version, options)
91
+ (options[:commit_message]) ? "v#{version} #{options[:commit_message]}" : "v#{version}"
92
+ end
87
93
 
88
- def self.commit(version, file, options)
89
- return unless File.directory?(".git")
90
- system("git add --update Gemfile.lock") if options[:bundle]
91
- system("git add --update #{file} && git commit -m '#{commit_message(version, options)}'")
92
- system("git tag -a -m 'Bump to v#{version}' v#{version}") if options[:tag]
93
- end
94
+ def commit(version, file, options)
95
+ return unless File.directory?(".git")
96
+ system("git add --update Gemfile.lock") if options[:bundle]
97
+ system("git add --update #{file} && git commit -m '#{commit_message(version, options)}'")
98
+ system("git tag -a -m 'Bump to v#{version}' v#{version}") if options[:tag]
99
+ end
94
100
 
95
- def self.replace(file, old, new)
96
- content = File.read(file)
97
- File.open(file, "w"){|f| f.write(content.sub(old, new)) }
98
- end
101
+ def replace(file, old, new)
102
+ content = File.read(file)
103
+ File.open(file, "w"){|f| f.write(content.sub(old, new)) }
104
+ end
99
105
 
100
- def self.current_info
101
- version, file = (
102
- version_from_version ||
103
- version_from_version_rb ||
104
- version_from_gemspec ||
105
- version_from_lib_rb ||
106
- version_from_chef ||
107
- raise(UnfoundVersionFileError)
108
- )
109
- raise UnfoundVersionError unless version
110
- [version, file]
111
- end
106
+ def current_info
107
+ version, file = (
108
+ version_from_version ||
109
+ version_from_version_rb ||
110
+ version_from_gemspec ||
111
+ version_from_lib_rb ||
112
+ version_from_chef ||
113
+ raise(UnfoundVersionFileError)
114
+ )
115
+ raise UnfoundVersionError unless version
116
+ [version, file]
117
+ end
112
118
 
113
- def self.version_from_gemspec
114
- return unless file = find_version_file("*.gemspec")
115
- version = File.read(file)[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1]
116
- return unless version = File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1] if version.nil?
117
- [version, file]
118
- end
119
+ def version_from_gemspec
120
+ return unless file = find_version_file("*.gemspec")
121
+ version = File.read(file)[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1]
122
+ return unless version = File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1] if version.nil?
123
+ [version, file]
124
+ end
119
125
 
120
- def self.version_from_version_rb
121
- files = Dir.glob("lib/**/version.rb")
122
- files.detect do |file|
123
- if version_and_file = extract_version_from_file(file)
124
- return version_and_file
126
+ def version_from_version_rb
127
+ files = Dir.glob("lib/**/version.rb")
128
+ files.detect do |file|
129
+ if version_and_file = extract_version_from_file(file)
130
+ return version_and_file
131
+ end
125
132
  end
126
133
  end
127
- end
128
134
 
129
- def self.version_from_version
130
- return unless file = find_version_file("VERSION")
131
- extract_version_from_file(file)
132
- end
135
+ def version_from_version
136
+ return unless file = find_version_file("VERSION")
137
+ extract_version_from_file(file)
138
+ end
133
139
 
134
- def self.version_from_lib_rb
135
- files = Dir.glob("lib/**/*.rb")
136
- file = files.detect do |file|
137
- File.read(file) =~ /^\s+VERSION = ['"](#{VERSION_REGEX})['"]/i
140
+ def version_from_lib_rb
141
+ files = Dir.glob("lib/**/*.rb")
142
+ file = files.detect do |f|
143
+ File.read(f) =~ /^\s+VERSION = ['"](#{VERSION_REGEX})['"]/i
144
+ end
145
+ [$1, file] if file
138
146
  end
139
- [$1, file] if file
140
- end
141
147
 
142
- def self.version_from_chef
143
- file = find_version_file("metadata.rb")
144
- return unless file && File.read(file) =~ /^version\s+(['"])(#{VERSION_REGEX})['"]/
145
- [$2, file]
146
- end
148
+ def version_from_chef
149
+ file = find_version_file("metadata.rb")
150
+ return unless file && File.read(file) =~ /^version\s+(['"])(#{VERSION_REGEX})['"]/
151
+ [$2, file]
152
+ end
147
153
 
148
- def self.extract_version_from_file(file)
149
- return unless version = File.read(file)[VERSION_REGEX]
150
- [version, file]
151
- end
154
+ def extract_version_from_file(file)
155
+ return unless version = File.read(file)[VERSION_REGEX]
156
+ [version, file]
157
+ end
152
158
 
153
- def self.find_version_file(pattern)
154
- files = Dir.glob(pattern)
155
- case files.size
156
- when 0 then nil
157
- when 1 then files.first
158
- else
159
- raise TooManyVersionFilesError, files.join(", ")
159
+ def find_version_file(pattern)
160
+ files = Dir.glob(pattern)
161
+ case files.size
162
+ when 0 then nil
163
+ when 1 then files.first
164
+ else
165
+ raise TooManyVersionFilesError, files.join(", ")
166
+ end
160
167
  end
161
- end
162
168
 
163
- def self.next_version(current, part)
164
- current, prerelease = current.split('-')
165
- major, minor, patch, *other = current.split('.')
166
- case part
167
- when "major"
168
- major, minor, patch, prerelease = major.succ, 0, 0, nil
169
- when "minor"
170
- minor, patch, prerelease = minor.succ, 0, nil
171
- when "patch"
172
- patch = patch.succ
173
- when "pre"
174
- prerelease.strip! if prerelease.respond_to? :strip
175
- prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
176
- else
177
- raise "unknown part #{part.inspect}"
178
- end
179
- version = [major, minor, patch, *other].compact.join('.')
180
- [version, prerelease].compact.join('-')
181
- end
169
+ def next_version(current, part)
170
+ current, prerelease = current.split('-')
171
+ major, minor, patch, *other = current.split('.')
172
+ case part
173
+ when "major"
174
+ major, minor, patch, prerelease = major.succ, 0, 0, nil
175
+ when "minor"
176
+ minor, patch, prerelease = minor.succ, 0, nil
177
+ when "patch"
178
+ patch = patch.succ
179
+ when "pre"
180
+ prerelease.strip! if prerelease.respond_to? :strip
181
+ prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
182
+ else
183
+ raise "unknown part #{part.inspect}"
184
+ end
185
+ version = [major, minor, patch, *other].compact.join('.')
186
+ [version, prerelease].compact.join('-')
187
+ end
182
188
 
183
- def self.under_version_control?(file)
184
- @all_files ||= `git ls-files`.split(/\r?\n/)
185
- @all_files.include?(file)
189
+ def under_version_control?(file)
190
+ @all_files ||= `git ls-files`.split(/\r?\n/)
191
+ @all_files.include?(file)
192
+ end
186
193
  end
187
194
  end
188
195
  end
@@ -15,7 +15,7 @@ namespace :bump do
15
15
  end
16
16
 
17
17
  task bump, :tag do |_task, args|
18
- run_bump.call(bump, :tag => args[:tag])
18
+ run_bump.call(bump, args)
19
19
  end
20
20
  end
21
21
 
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Marcilhacy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: 10.0.0
33
+ version: '11.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: 10.0.0
40
+ version: '11.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '2.0'
47
+ version: '3.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '2.0'
54
+ version: '3.0'
41
55
  description:
42
56
  email: g.marcilhacy@gmail.com
43
57
  executables:
@@ -69,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
83
  version: '0'
70
84
  requirements: []
71
85
  rubyforge_project:
72
- rubygems_version: 2.2.2
86
+ rubygems_version: 2.4.5.1
73
87
  signing_key:
74
88
  specification_version: 4
75
89
  summary: Bump your gem version file