bump 0.6.0 → 0.10.0

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 +5 -5
  2. data/README.md +101 -34
  3. data/bin/bump +27 -20
  4. data/lib/bump.rb +152 -53
  5. data/lib/bump/tasks.rb +18 -6
  6. metadata +22 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e51fb92b564a485b205bc5e725905e6f7bd4420e
4
- data.tar.gz: a4a95a2a928ded911a5b8e47e83deb8d03dc374a
2
+ SHA256:
3
+ metadata.gz: edcda9c3ea370efa0927b59c72718d997c204026139349f9c3ed8a5d62b688d8
4
+ data.tar.gz: c866f3dd937aad196d1bc1204115698f4f28ebc027abdca2ea07ded1ede4ef3d
5
5
  SHA512:
6
- metadata.gz: 0cc285263fa2ba6afe4bf7f5c255255acb082256e113917a8f64fdeb2b4d5f11376167cf602bba2eaca8bda9e612479e5a65d8b69cf83da1b079d4c1ea782d76
7
- data.tar.gz: d71c9c942424c8a59a6f2fc41d2953266ae2465ef242127cea2a3946f929ee56d53710ae36a695e596288a9782663fa62fef6422ba7d5b72e70e4e9d8dfae11c
6
+ metadata.gz: d911a104915b66431136fece97b24853b039bddde41f30839a95d104647280e108f567da9359f2740b37d625ad81941a4fbf64a5e9c8914475bb95b86e21ecff
7
+ data.tar.gz: 2ca0ed62d336d9db203a7ee864498e14e8eab70316179ae92649803a426d2a6f75f1349a9c5d5ecf5ccb9b9431004f7a05d2b7edbb854512f2ea62408c682632
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  [![Build Status](https://travis-ci.org/gregorym/bump.svg)](https://travis-ci.org/gregorym/bump)
2
2
  [![Gem Version](https://badge.fury.io/rb/bump.svg)](http://badge.fury.io/rb/bump)
3
3
 
4
- # Introduction
5
- Bump is a gem that will simplify the way you build gems and chef-cookbooks.
4
+ A gem to bump versions of gems and chef-cookbooks.
6
5
 
6
+ - bumps version major / minor / patch / pre
7
+ - bundles
8
+ - commits changes
7
9
 
8
10
  # Installation
9
11
 
@@ -11,58 +13,116 @@ Bump is a gem that will simplify the way you build gems and chef-cookbooks.
11
13
 
12
14
  # Usage
13
15
 
14
- Current version:
16
+ ### Show current version
15
17
 
16
18
  bump current
17
19
 
18
- Current version: 0.1.2
20
+ > 0.1.2
19
21
 
20
- Bump (major, minor, patch, pre):
22
+ ### Bump (major, minor, patch, pre)
21
23
 
22
24
  bump patch
23
25
 
24
- Bump version 0.1.2 to 0.1.3
26
+ > Bump version 0.1.2 to 0.1.3
25
27
 
26
- ### Options
28
+ ### Show next version
29
+
30
+ bump show-next patch
31
+
32
+ > 0.1.3
33
+
34
+ ### Show version file path
35
+
36
+ bump file
37
+
38
+ > lib/foo/version.rb
39
+
40
+ ## Options
41
+
42
+ ### `--no-commit`
43
+
44
+ Do not commit after bumping.
27
45
 
28
- ### --no-commit
29
- If you don't want to make a commit after bumping, add the `--no-commit` option.
30
-
31
46
  bump patch --no-commit
32
47
 
33
- ### --tag
34
- Will add a git tag (if the current project is a git repository and `--no-commit` has not been given).
48
+ ### `--tag`
49
+
50
+ Will add a git tag like `v1.2.3` (if the current project is a git repository and `--no-commit` has not been given).
35
51
 
36
52
  bump patch --tag
37
53
 
38
- ### --no-bundle
39
- If you don't want to run the `bundle` command after bumping, add the `--no-bundle` option.
40
-
54
+ The `--tag-prefix` option can change the tag prefix:
55
+
56
+ bump patch --tag --tag-prefix v- # tag as v-1.2.3
57
+ bump patch --tag --tag-prefix "" # tag as 1.2.3
58
+
59
+ ### `--no-bundle`
60
+
61
+ Do not run `bundle` command after bumping.
62
+
41
63
  bump patch --no-bundle
42
64
 
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.
65
+ ### `--replace-in`
66
+
67
+ Bump the version in additional files.
68
+
69
+ bump patch --replace-in Readme.md
70
+
71
+ ### `--commit-message [MSG], -m [MSG]`
45
72
 
46
- bump patch --commit-message [no-ci]
73
+ Append additional information to the commit message.
74
+
75
+ bump patch --commit-message "Something extra"
47
76
 
48
77
  or
49
78
 
50
- bump patch -m [no-cli]
79
+ bump patch -m "Something extra"
80
+
81
+ ### `--changelog`
82
+
83
+ Updates `CHANGELOG.md` when bumping.
84
+ This requires a heading (starting with `##`) that includes the previous version and a heading above that, for example:
85
+
86
+ ```markdown
87
+ ### Next
88
+ - Added bar
89
+
90
+ ### v0.0.0 - 2019-12-24
91
+ - Added foo
92
+ ```
93
+
94
+ ### `--edit-changelog`
95
+
96
+ Updates CHANGELOG.md when bumping (see above), and
97
+ opens the changelog in an editor specified in `$EDITOR` (or `vi`),
98
+ then waits for the editor to be closed and continues.
51
99
 
52
- ### Rake
100
+ ```bash
101
+ EDITOR="subl -n -w" bump patch --edit-changelog
102
+ ```
103
+
104
+ ## Rake
53
105
 
54
- ```Ruby
106
+ ```ruby
55
107
  # Rakefile
56
108
  require "bump/tasks"
57
109
 
58
110
  #
59
- # if you want to always tag the version, add:
60
- # Bump.tag_by_default = true
111
+ # do not always tag the version
112
+ # Bump.tag_by_default = false
61
113
  #
62
-
114
+ # bump the version in additional files
115
+ # Bump.replace_in_default = ["Readme.md"]
116
+ #
117
+ # Maintain changelog:
118
+ # Bump.changelog = true
119
+ # Opens the changelog in an editor when bumping
120
+ # Bump.changelog = :editor
63
121
  ```
64
-
122
+
65
123
  rake bump:current # display current version
124
+ rake bump:show-next INCREMENT=minor # display next minor version
125
+ rake bump:file # display version file path
66
126
 
67
127
  # bumping using defaults for `COMMIT`, `TAG`, and `BUNDLE`
68
128
  rake bump:major
@@ -72,25 +132,32 @@ require "bump/tasks"
72
132
 
73
133
  # bumping with option(s)
74
134
  rake bump:patch TAG=false BUNDLE=false # commit, but don't tag or run `bundle`
135
+ rake bump:patch TAG=true TAG_PREFIX=v- # tag with a prefix 'v-' ex. the tag will look like v-0.0.1
75
136
  rake bump:patch COMMIT=false TAG=false # don't commit, don't tag
76
137
  rake bump:minor BUNDLE=false # don't run `bundle`
77
138
 
78
- ### Ruby
79
- ```Ruby
139
+ ## Ruby
140
+
141
+ ```ruby
80
142
  require "bump"
81
143
  Bump::Bump.current # -> "1.2.3"
144
+ Bump::Bump.next_version("patch") # -> "1.2.4"
145
+ Bump::Bump.file # -> "lib/foo/version.rb"
82
146
  Bump::Bump.run("patch") # -> version changed
147
+ Bump::Bump.run("patch", tag: true, tag_prefix: 'v-') # -> version changed with tagging with '-v' as prefix
83
148
  Bump::Bump.run("patch", commit: false, bundle:false, tag:false) # -> version changed with options
84
149
  Bump::Bump.run("patch", commit_message: '[no ci]') # -> creates a commit message with 'v1.2.3 [no ci]' instead of default: 'v1.2.3'
85
150
  ```
86
151
 
87
152
  # Supported locations
88
- - VERSION file with "1.2.3"
89
- - gemspec with `gem.version = "1.2.3"` or `Gem:Specification.new "gem-name", "1.2.3" do`
90
- - lib/**/version.rb file with `VERSION = "1.2.3"`
91
- - metadata.rb with `version "1.2.3"`
92
- - `VERSION = "1.2.3"` in lib/**/*.rb
153
+
154
+ - `VERSION` file with `1.2.3`
155
+ - `gemspec` with `gem.version = "1.2.3"` or `Gem:Specification.new "gem-name", "1.2.3" do`
156
+ - `lib/**/version.rb` file with `VERSION = "1.2.3"`
157
+ - `metadata.rb` with `version "1.2.3"`
158
+ - `VERSION = "1.2.3"` in `lib/**/*.rb`
93
159
 
94
160
  # Author
95
- Gregory<br/>
96
- License: MIT<br/>
161
+
162
+ Gregory<br>
163
+ License: MIT
data/bin/bump CHANGED
@@ -1,36 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'optparse'
5
+ require 'shellwords'
3
6
 
4
7
  options = {}
5
8
  OptionParser.new do |opts|
6
- opts.banner = <<BANNER
7
- Bump your gem version.
9
+ opts.banner = <<-BANNER.gsub(/^ /, "")
10
+ Bump your gem version.
8
11
 
9
- Usage:
10
- bump current # show current version
11
- bump pre # increase prerelease version of your gem (1.0.0-X) [alpha, beta, rc, ]
12
- bump patch # increase patch version of your gem (1.0.X)
13
- bump minor # increase minor version of your gem (1.X.0)
14
- bump major # increase major version of your gem (X.0.0)
15
- bump set 1.2.3 # set the version number to the given value
12
+ Usage:
13
+ bump current # show current version
14
+ bump show-next INCREMENT # show next (pre|patch|minor|major) version of your gem
15
+ bump file # show version file path
16
+ bump pre # increase prerelease version of your gem (1.0.0-X) [alpha, beta, rc, ]
17
+ bump patch # increase patch version of your gem (1.0.X)
18
+ bump minor # increase minor version of your gem (1.X.0)
19
+ bump major # increase major version of your gem (X.0.0)
20
+ bump set 1.2.3 # set the version number to the given value
16
21
 
17
- Options:
18
- BANNER
22
+ Options:
23
+ BANNER
19
24
  opts.on("--no-commit", "Do not make a commit.") { options[:commit] = false }
20
- opts.on("-m","--commit-message [MSG]", "Append MSG to the commit message.") {|msg| options[:commit_message] = msg }
25
+ opts.on("-m", "--commit-message MSG", String, "Append MSG to the commit message.") { |msg| options[:commit_message] = msg }
21
26
  opts.on("--no-bundle", "Do not bundle.") { options[:bundle] = false }
22
27
  opts.on("--tag", "Create git tag from version (only if commit is true).") { options[:tag] = true }
23
- opts.on("-h", "--help","Show this.") { puts opts; exit }
28
+ opts.on("--tag-prefix TAG_PREFIX", "Prefix the tag with this string, ex. 'v'") { |tag_prefix| options[:tag_prefix] = tag_prefix }
29
+ opts.on("--replace-in FILE", String, "Replace old version with the new version additionally in this file") { |f| (options[:replace_in] ||= []) << f }
30
+ opts.on("--changelog", "Update CHANGELOG.md") { options[:changelog] = true }
31
+ opts.on("--edit-changelog", "Use $EDITOR to open changelog before committing, e.g. 'subl -n -w' or 'nano'.") { options[:changelog] = :editor }
32
+ opts.on("--value-only", "Do not prefix the output with any descriptive text") { options[:value_only] = true }
33
+ opts.on("-h", "--help", "Show this.") { puts opts; exit }
24
34
  end.parse!
25
35
 
26
- unless (ARGV.size == 1 && ARGV.first != "set") || (ARGV.size == 2 && ARGV.first == "set")
27
- puts "Usage instructions: bump --help"
28
- exit 1
29
- end
36
+ valid_argv = ["set", "show-next"].include?(ARGV.first) ? 2 : 1
37
+ abort "Usage instructions: bump --help" unless ARGV.size == valid_argv
30
38
 
31
- if ARGV.first == "set"
32
- options[:version] = ARGV[1]
33
- end
39
+ options[:version] = ARGV[1] if ARGV[0] == "set"
40
+ options[:increment] = ARGV[1] if ARGV[0] == "show-next"
34
41
 
35
42
  require File.dirname(__FILE__) + '/../lib/bump'
36
43
  output, status = Bump::Bump.run(ARGV.first, options)
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bump
4
+ class InvalidIncrementError < StandardError; end
2
5
  class InvalidOptionError < StandardError; end
3
6
  class InvalidVersionError < StandardError; end
4
7
  class UnfoundVersionError < StandardError; end
@@ -7,39 +10,52 @@ module Bump
7
10
  class RakeArgumentsDeprecatedError < StandardError; end
8
11
 
9
12
  class <<self
10
- attr_accessor :tag_by_default
13
+ attr_accessor :tag_by_default, :replace_in_default, :changelog
11
14
  end
12
15
 
13
16
  class Bump
14
- BUMPS = %w(major minor patch pre)
15
- PRERELEASE = ["alpha","beta","rc",nil]
16
- OPTIONS = BUMPS | ["set", "current"]
17
- VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/
17
+ BUMPS = ["major", "minor", "patch", "pre"].freeze
18
+ PRERELEASE = ["alpha", "beta", "rc", nil].freeze
19
+ OPTIONS = BUMPS | ["set", "current", "file"]
20
+ VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/.freeze
18
21
 
19
22
  class << self
20
-
21
23
  def defaults
22
24
  {
23
- :tag => ::Bump.tag_by_default,
24
- :commit => true,
25
- :bundle => File.exist?("Gemfile")
25
+ tag: ::Bump.tag_by_default,
26
+ tag_prefix: 'v',
27
+ commit: true,
28
+ changelog: ::Bump.changelog || false, # TODO: default to true with opt-out once it gets more stable
29
+ bundle: File.exist?("Gemfile"),
30
+ replace_in: ::Bump.replace_in_default || []
26
31
  }
27
32
  end
28
33
 
29
- def run(bump, options={})
34
+ def run(bump, options = {})
30
35
  options = defaults.merge(options)
36
+ options[:commit] = false unless File.directory?(".git")
31
37
 
32
38
  case bump
33
39
  when *BUMPS
34
40
  bump_part(bump, options)
35
41
  when "set"
36
42
  raise InvalidVersionError unless options[:version]
43
+
37
44
  bump_set(options[:version], options)
38
45
  when "current"
39
- ["Current version: #{current}", 0]
46
+ [current, 0]
47
+ when "show-next"
48
+ increment = options[:increment]
49
+ raise InvalidIncrementError unless BUMPS.include?(increment)
50
+
51
+ [next_version(increment), 0]
52
+ when "file"
53
+ [file, 0]
40
54
  else
41
55
  raise InvalidOptionError
42
56
  end
57
+ rescue InvalidIncrementError
58
+ ["Invalid increment. Choose between #{BUMPS.join(',')}.", 1]
43
59
  rescue InvalidOptionError
44
60
  ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
45
61
  rescue InvalidVersionError
@@ -56,11 +72,40 @@ module Bump
56
72
  current_info.first
57
73
  end
58
74
 
75
+ def next_version(increment, current = Bump.current)
76
+ current, prerelease = current.split('-')
77
+ major, minor, patch, *other = current.split('.')
78
+ case increment
79
+ when "major"
80
+ major = major.succ
81
+ minor = 0
82
+ patch = 0
83
+ prerelease = nil
84
+ when "minor"
85
+ minor = minor.succ
86
+ patch = 0
87
+ prerelease = nil
88
+ when "patch"
89
+ patch = patch.succ
90
+ when "pre"
91
+ prerelease.strip! if prerelease.respond_to? :strip
92
+ prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
93
+ else
94
+ raise InvalidIncrementError
95
+ end
96
+ version = [major, minor, patch, *other].compact.join('.')
97
+ [version, prerelease].compact.join('-')
98
+ end
99
+
100
+ def file
101
+ current_info.last
102
+ end
103
+
59
104
  def parse_cli_options!(options)
60
105
  options.each do |key, value|
61
106
  options[key] = parse_cli_options_value(value)
62
107
  end
63
- options.delete_if{|key, value| value.nil?}
108
+ options.delete_if { |_key, value| value.nil? }
64
109
  end
65
110
 
66
111
  private
@@ -76,27 +121,62 @@ module Bump
76
121
  end
77
122
 
78
123
  def bump(file, current, next_version, options)
79
- replace(file, current, next_version)
80
- if options[:bundle] and Dir.glob('*.gemspec').any? and under_version_control?("Gemfile.lock")
124
+ # bump in files that need to change
125
+ [file, *options[:replace_in]].each do |f|
126
+ return ["Unable to find version #{current} in #{f}", 1] unless replace f, current, next_version
127
+
128
+ git_add f if options[:commit]
129
+ end
130
+
131
+ # bundle if needed
132
+ if options[:bundle] && Dir.glob('*.gemspec').any? && under_version_control?("Gemfile.lock")
81
133
  bundler_with_clean_env do
82
134
  return ["Bundle error", 1] unless system("bundle")
135
+
136
+ git_add "Gemfile.lock" if options[:commit]
83
137
  end
84
138
  end
85
- commit(next_version, file, options) if options[:commit]
86
- ["Bump version #{current} to #{next_version}", 0]
139
+
140
+ # changelog if needed
141
+ if options[:changelog]
142
+ log = Dir["CHANGELOG.md"].first
143
+ return ["Did not find CHANGELOG.md", 1] unless log
144
+
145
+ error = bump_changelog(log, next_version)
146
+ return [error, 1] if error
147
+
148
+ open_changelog(log) if options[:changelog] == :editor
149
+
150
+ git_add log if options[:commit]
151
+ end
152
+
153
+ # commit staged changes
154
+ commit next_version, options if options[:commit]
155
+
156
+ # tell user the result
157
+ [next_version, 0]
158
+ end
159
+
160
+ def open_changelog(log)
161
+ editor = ENV['EDITOR'] || "vi"
162
+ system "#{editor} #{log}"
87
163
  end
88
164
 
89
165
  def bundler_with_clean_env(&block)
90
166
  if defined?(Bundler)
91
- Bundler.with_clean_env(&block)
167
+ if Bundler.respond_to?(:with_unbundled_env)
168
+ Bundler.with_unbundled_env(&block)
169
+ else
170
+ Bundler.with_clean_env(&block)
171
+ end
92
172
  else
93
173
  yield
94
174
  end
95
175
  end
96
176
 
97
- def bump_part(part, options)
177
+ def bump_part(increment, options)
98
178
  current, file = current_info
99
- next_version = next_version(current, part)
179
+ next_version = next_version(increment, current)
100
180
  bump(file, current, next_version, options)
101
181
  end
102
182
 
@@ -105,20 +185,49 @@ module Bump
105
185
  bump(file, current, next_version, options)
106
186
  end
107
187
 
188
+ def bump_changelog(file, current)
189
+ parts = File.read(file).split(/(^##+.*)/) # headlines and their content
190
+ prev_index = parts.index { |p| p =~ /(^##+.*(\d+\.\d+\.\d+(\.[a-z]+)?).*)/ } # position of previous version
191
+ return "Unable to find previous version in CHANGELOG.md" unless prev_index
192
+
193
+ # reuse the same style by just swapping the numbers
194
+ new_heading = parts[prev_index].sub($2, current)
195
+ # add current date if previous heading used that
196
+ new_heading.sub!(/\d\d\d\d-\d\d-\d\d/, Time.now.strftime('%Y-%m-%d'))
197
+
198
+ if prev_index < 2
199
+ # previous version is first '##' element (no '## Next' present), add line feed after version to avoid
200
+ # '## v1.0.1## v1.0.0'
201
+ parts.insert prev_index - 1, new_heading + "\n"
202
+ else
203
+ # put our new heading underneath the "Next" heading, which should be above the last version
204
+ parts.insert prev_index - 1, "\n" + new_heading
205
+ end
206
+
207
+ File.write file, parts.join("")
208
+ nil
209
+ end
210
+
108
211
  def commit_message(version, options)
109
- (options[:commit_message]) ? "v#{version} #{options[:commit_message]}" : "v#{version}"
212
+ tag = "#{options[:tag_prefix]}#{version}"
213
+ options[:commit_message] ? "#{tag} #{options[:commit_message]}" : tag
110
214
  end
111
215
 
112
- def commit(version, file, options)
113
- return unless File.directory?(".git")
114
- system("git add --update Gemfile.lock") if options[:bundle]
115
- system("git add --update #{file} && git commit -m '#{commit_message(version, options)}'")
116
- system("git tag -a -m 'Bump to v#{version}' v#{version}") if options[:tag]
216
+ def commit(version, options)
217
+ tag = "#{options[:tag_prefix]}#{version}"
218
+ system("git", "commit", "-m", commit_message(version, options))
219
+ system("git", "tag", "-a", "-m", "Bump to #{tag}", tag) if options[:tag]
220
+ end
221
+
222
+ def git_add(file)
223
+ system("git", "add", "--update", file)
117
224
  end
118
225
 
119
226
  def replace(file, old, new)
120
227
  content = File.read(file)
121
- File.open(file, "w"){|f| f.write(content.sub(old, new)) }
228
+ return unless content.sub!(old, new)
229
+
230
+ File.write(file, content)
122
231
  end
123
232
 
124
233
  def current_info
@@ -126,18 +235,25 @@ module Bump
126
235
  version_from_version ||
127
236
  version_from_version_rb ||
128
237
  version_from_gemspec ||
129
- version_from_lib_rb ||
130
- version_from_chef ||
238
+ version_from_lib_rb ||
239
+ version_from_chef ||
131
240
  raise(UnfoundVersionFileError)
132
241
  )
133
242
  raise UnfoundVersionError unless version
243
+
134
244
  [version, file]
135
245
  end
136
246
 
137
247
  def version_from_gemspec
138
- return unless file = find_version_file("*.gemspec")
139
- version = File.read(file)[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1]
140
- return unless version = File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1] if version.nil?
248
+ return unless file = find_version_file("*.gemspec")
249
+
250
+ content = File.read(file)
251
+ version = (
252
+ content[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1] ||
253
+ File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1]
254
+ )
255
+ return unless version
256
+
141
257
  [version, file]
142
258
  end
143
259
 
@@ -152,6 +268,7 @@ module Bump
152
268
 
153
269
  def version_from_version
154
270
  return unless file = find_version_file("VERSION")
271
+
155
272
  extract_version_from_file(file)
156
273
  end
157
274
 
@@ -160,17 +277,19 @@ module Bump
160
277
  file = files.detect do |f|
161
278
  File.read(f) =~ /^\s+VERSION = ['"](#{VERSION_REGEX})['"]/i
162
279
  end
163
- [$1, file] if file
280
+ [Regexp.last_match(1), file] if file
164
281
  end
165
282
 
166
283
  def version_from_chef
167
284
  file = find_version_file("metadata.rb")
168
285
  return unless file && File.read(file) =~ /^version\s+(['"])(#{VERSION_REGEX})['"]/
169
- [$2, file]
286
+
287
+ [Regexp.last_match(2), file]
170
288
  end
171
289
 
172
290
  def extract_version_from_file(file)
173
291
  return unless version = File.read(file)[VERSION_REGEX]
292
+
174
293
  [version, file]
175
294
  end
176
295
 
@@ -184,26 +303,6 @@ module Bump
184
303
  end
185
304
  end
186
305
 
187
- def next_version(current, part)
188
- current, prerelease = current.split('-')
189
- major, minor, patch, *other = current.split('.')
190
- case part
191
- when "major"
192
- major, minor, patch, prerelease = major.succ, 0, 0, nil
193
- when "minor"
194
- minor, patch, prerelease = minor.succ, 0, nil
195
- when "patch"
196
- patch = patch.succ
197
- when "pre"
198
- prerelease.strip! if prerelease.respond_to? :strip
199
- prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
200
- else
201
- raise "unknown part #{part.inspect}"
202
- end
203
- version = [major, minor, patch, *other].compact.join('.')
204
- [version, prerelease].compact.join('-')
205
- end
206
-
207
306
  def under_version_control?(file)
208
307
  @all_files ||= `git ls-files`.split(/\r?\n/)
209
308
  @all_files.include?(file)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bump"
2
4
 
3
5
  namespace :bump do
@@ -7,20 +9,30 @@ namespace :bump do
7
9
  abort unless status == 0
8
10
  end
9
11
 
10
- (Bump::Bump::BUMPS + ["current"]).each do |bump|
12
+ (Bump::Bump::BUMPS + ["current", "file", "show-next"]).each do |bump|
11
13
  if bump == "current"
12
14
  desc "Show current gem version"
15
+ elsif bump == "show-next"
16
+ desc "Show next #{Bump::Bump::BUMPS.join('|')} version."
17
+ elsif bump == "file"
18
+ desc "Show version file path"
13
19
  else
14
20
  desc "Bump #{bump} part of gem version"
15
21
  end
16
22
 
17
- task bump, :tag do |_task, args|
18
- raise RakeArgumentsDeprecatedError,
19
- "rake arguments are deprecated, use TAG=false to disable tagging" if args.tag
23
+ task bump, :no_args do |_task, args|
24
+ if args.no_args
25
+ raise(
26
+ RakeArgumentsDeprecatedError,
27
+ "rake arguments are deprecated, use TAG=false to disable tagging"
28
+ )
29
+ end
20
30
  options = {
21
31
  tag: ENV['TAG'],
32
+ tag_prefix: ENV['TAG_PREFIX'],
22
33
  commit: ENV['COMMIT'],
23
- bundle: ENV['BUNDLE']
34
+ bundle: ENV['BUNDLE'],
35
+ increment: ENV['INCREMENT']
24
36
  }
25
37
  run_bump.call(bump, Bump::Bump.parse_cli_options!(options))
26
38
  end
@@ -28,6 +40,6 @@ namespace :bump do
28
40
 
29
41
  desc "Sets the version number using the VERSION environment variable"
30
42
  task :set do
31
- run_bump.call("set", :version => ENV['VERSION'])
43
+ run_bump.call("set", version: ENV['VERSION'])
32
44
  end
33
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Marcilhacy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,21 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description:
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
56
70
  email: g.marcilhacy@gmail.com
57
71
  executables:
58
72
  - bump
@@ -67,7 +81,7 @@ homepage: https://github.com/gregorym/bump
67
81
  licenses:
68
82
  - MIT
69
83
  metadata: {}
70
- post_install_message:
84
+ post_install_message:
71
85
  rdoc_options: []
72
86
  require_paths:
73
87
  - lib
@@ -75,16 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
89
  requirements:
76
90
  - - ">="
77
91
  - !ruby/object:Gem::Version
78
- version: 1.9.3
92
+ version: 2.3.0
79
93
  required_rubygems_version: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - ">="
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0'
84
98
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.4.5.1
87
- signing_key:
99
+ rubygems_version: 3.1.2
100
+ signing_key:
88
101
  specification_version: 4
89
102
  summary: Bump your gem version file
90
103
  test_files: []