bump 0.7.0 → 0.8.0

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -1
  3. data/bin/bump +13 -11
  4. data/lib/bump.rb +40 -30
  5. data/lib/bump/tasks.rb +6 -2
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17af1c7f47a19abd1ace6aee8345088421e47453
4
- data.tar.gz: ab54a763ebe1126c7b0322b70373818fa89620cb
3
+ metadata.gz: 83453453cffa0d63a765fc4fb7aa084d7a992da4
4
+ data.tar.gz: f4db814fff42565eee6927dc941b026c282939df
5
5
  SHA512:
6
- metadata.gz: bba34c35004146cb1a70caa0393755f983dab7ea2008fb540297a48ce6f06054e5ff4b2db6c4022c3e563494ba60224a3d856aec27a9763ecf01bf163de2e6f8
7
- data.tar.gz: 07c299ca4ee9e13c0b7d35f65119dbd93dc55fac9d68f53b6351e89f6e74dff09c48a568679295c780768b64177ae68b3805bba65ceee4dc4650c40a69ffe5b9
6
+ metadata.gz: 9e74704154155f9ddb50c45b40a802b6a7a0088e07a7dd073fe1ee11e0580765f1a7add70ababfc247580230a700c3707d4ff75afea36f0bd8dac9c1c11792af
7
+ data.tar.gz: 9e892e2d1e59aa12abeab19e5fdff8b54594aa9c8912404d0fd503f64a0628a4601ae81d8fbe63406663e32c3bb6e70fe295234f773b017c0e4fe64e085e5c22
data/README.md CHANGED
@@ -17,6 +17,12 @@ Current version:
17
17
 
18
18
  > Current version: 0.1.2
19
19
 
20
+ Show next patch version:
21
+
22
+ bump show-next patch
23
+
24
+ > Next patch version: 0.1.3
25
+
20
26
  Version file path:
21
27
 
22
28
  bump file
@@ -39,10 +45,15 @@ If you don't want to make a commit after bumping, add the `--no-commit` option.
39
45
 
40
46
  ### `--tag`
41
47
 
42
- Will add a git tag (if the current project is a git repository and `--no-commit` has not been given).
48
+ Will add a git tag like `v1.2.3` (if the current project is a git repository and `--no-commit` has not been given).
43
49
 
44
50
  bump patch --tag
45
51
 
52
+ The `--tag-prefix` option can change the tag prefix:
53
+
54
+ bump patch --tag --tag-prefix v- # tag as v-1.2.3
55
+ bump patch --tag --tag-prefix "" # tag as 1.2.3
56
+
46
57
  ### `--no-bundle`
47
58
 
48
59
  If you don't want to run the `bundle` command after bumping, add the `--no-bundle` option.
@@ -81,6 +92,7 @@ require "bump/tasks"
81
92
  ```
82
93
 
83
94
  rake bump:current # display current version
95
+ rake bump:show-next INCREMENT=minor # display next minor version
84
96
  rake bump:file # display version file path
85
97
 
86
98
  # bumping using defaults for `COMMIT`, `TAG`, and `BUNDLE`
@@ -91,6 +103,7 @@ require "bump/tasks"
91
103
 
92
104
  # bumping with option(s)
93
105
  rake bump:patch TAG=false BUNDLE=false # commit, but don't tag or run `bundle`
106
+ rake bump:patch TAG=true TAG_PREFIX=v- # tag with a prefix 'v-' ex. the tag will look like v-0.0.1
94
107
  rake bump:patch COMMIT=false TAG=false # don't commit, don't tag
95
108
  rake bump:minor BUNDLE=false # don't run `bundle`
96
109
 
@@ -99,8 +112,10 @@ require "bump/tasks"
99
112
  ```ruby
100
113
  require "bump"
101
114
  Bump::Bump.current # -> "1.2.3"
115
+ Bump::Bump.next_version("patch") # -> "1.2.4"
102
116
  Bump::Bump.file # -> "lib/foo/version.rb"
103
117
  Bump::Bump.run("patch") # -> version changed
118
+ Bump::Bump.run("patch", tag: true, tag_prefix: 'v-') # -> version changed with tagging with '-v' as prefix
104
119
  Bump::Bump.run("patch", commit: false, bundle:false, tag:false) # -> version changed with options
105
120
  Bump::Bump.run("patch", commit_message: '[no ci]') # -> creates a commit message with 'v1.2.3 [no ci]' instead of default: 'v1.2.3'
106
121
  ```
data/bin/bump CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'optparse'
3
+ require 'shellwords'
3
4
 
4
5
  options = {}
5
6
  OptionParser.new do |opts|
@@ -7,13 +8,14 @@ OptionParser.new do |opts|
7
8
  Bump your gem version.
8
9
 
9
10
  Usage:
10
- bump current # show current version
11
- bump file # show version file path
12
- bump pre # increase prerelease version of your gem (1.0.0-X) [alpha, beta, rc, ]
13
- bump patch # increase patch version of your gem (1.0.X)
14
- bump minor # increase minor version of your gem (1.X.0)
15
- bump major # increase major version of your gem (X.0.0)
16
- bump set 1.2.3 # set the version number to the given value
11
+ bump current # show current version
12
+ bump show-next INCREMENT # show next (pre|patch|minor|major) version of your gem
13
+ bump file # show version file path
14
+ bump pre # increase prerelease version of your gem (1.0.0-X) [alpha, beta, rc, ]
15
+ bump patch # increase patch version of your gem (1.0.X)
16
+ bump minor # increase minor version of your gem (1.X.0)
17
+ bump major # increase major version of your gem (X.0.0)
18
+ bump set 1.2.3 # set the version number to the given value
17
19
 
18
20
  Options:
19
21
  BANNER
@@ -21,16 +23,16 @@ OptionParser.new do |opts|
21
23
  opts.on("-m", "--commit-message MSG", String, "Append MSG to the commit message.") { |msg| options[:commit_message] = msg }
22
24
  opts.on("--no-bundle", "Do not bundle.") { options[:bundle] = false }
23
25
  opts.on("--tag", "Create git tag from version (only if commit is true).") { options[:tag] = true }
26
+ opts.on("--tag-prefix TAG_PREFIX", "Prefix the tag with this string, ex. 'v'") { |tag_prefix| options[:tag_prefix] = tag_prefix }
24
27
  opts.on("--replace-in FILE", String, "Replace old version with the new version additionally in this file") { |f| (options[:replace_in] ||= []) << f }
25
28
  opts.on("-h", "--help", "Show this.") { puts opts; exit }
26
29
  end.parse!
27
30
 
28
- unless (ARGV.size == 1 && ARGV.first != "set") || (ARGV.size == 2 && ARGV.first == "set")
29
- puts "Usage instructions: bump --help"
30
- exit 1
31
- end
31
+ valid_argv = ["set", "show-next"].include?(ARGV.first) ? 2 : 1
32
+ abort "Usage instructions: bump --help" unless ARGV.size == valid_argv
32
33
 
33
34
  options[:version] = ARGV[1] if ARGV[0] == "set"
35
+ options[:increment] = ARGV[1] if ARGV[0] == "show-next"
34
36
 
35
37
  require File.dirname(__FILE__) + '/../lib/bump'
36
38
  output, status = Bump::Bump.run(ARGV.first, options)
@@ -1,4 +1,5 @@
1
1
  module Bump
2
+ class InvalidIncrementError < StandardError; end
2
3
  class InvalidOptionError < StandardError; end
3
4
  class InvalidVersionError < StandardError; end
4
5
  class UnfoundVersionError < StandardError; end
@@ -20,6 +21,7 @@ module Bump
20
21
  def defaults
21
22
  {
22
23
  tag: ::Bump.tag_by_default,
24
+ tag_prefix: 'v',
23
25
  commit: true,
24
26
  bundle: File.exist?("Gemfile"),
25
27
  replace_in: ::Bump.replace_in_default || []
@@ -39,11 +41,18 @@ module Bump
39
41
  bump_set(options[:version], options)
40
42
  when "current"
41
43
  ["Current version: #{current}", 0]
44
+ when "show-next"
45
+ increment = options[:increment]
46
+ raise InvalidIncrementError unless BUMPS.include?(increment)
47
+
48
+ [next_version(increment), 0]
42
49
  when "file"
43
50
  ["Version file path: #{file}", 0]
44
51
  else
45
52
  raise InvalidOptionError
46
53
  end
54
+ rescue InvalidIncrementError
55
+ ["Invalid increment. Choose between #{BUMPS.join(',')}.", 1]
47
56
  rescue InvalidOptionError
48
57
  ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
49
58
  rescue InvalidVersionError
@@ -60,6 +69,31 @@ module Bump
60
69
  current_info.first
61
70
  end
62
71
 
72
+ def next_version(increment, current = Bump.current)
73
+ current, prerelease = current.split('-')
74
+ major, minor, patch, *other = current.split('.')
75
+ case increment
76
+ when "major"
77
+ major = major.succ
78
+ minor = 0
79
+ patch = 0
80
+ prerelease = nil
81
+ when "minor"
82
+ minor = minor.succ
83
+ patch = 0
84
+ prerelease = nil
85
+ when "patch"
86
+ patch = patch.succ
87
+ when "pre"
88
+ prerelease.strip! if prerelease.respond_to? :strip
89
+ prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
90
+ else
91
+ raise InvalidIncrementError
92
+ end
93
+ version = [major, minor, patch, *other].compact.join('.')
94
+ [version, prerelease].compact.join('-')
95
+ end
96
+
63
97
  def file
64
98
  current_info.last
65
99
  end
@@ -115,9 +149,9 @@ module Bump
115
149
  end
116
150
  end
117
151
 
118
- def bump_part(part, options)
152
+ def bump_part(increment, options)
119
153
  current, file = current_info
120
- next_version = next_version(current, part)
154
+ next_version = next_version(increment, current)
121
155
  bump(file, current, next_version, options)
122
156
  end
123
157
 
@@ -127,13 +161,14 @@ module Bump
127
161
  end
128
162
 
129
163
  def commit_message(version, options)
130
- base = "v#{version}"
131
- options[:commit_message] ? "#{base} #{options[:commit_message]}" : base
164
+ tag = "#{options[:tag_prefix]}#{version}"
165
+ options[:commit_message] ? "#{tag} #{options[:commit_message]}" : tag
132
166
  end
133
167
 
134
168
  def commit(version, options)
169
+ tag = "#{options[:tag_prefix]}#{version}"
135
170
  system("git", "commit", "-m", commit_message(version, options))
136
- system("git", "tag", "-a", "-m", "Bump to v#{version}", "v#{version}") if options[:tag]
171
+ system("git", "tag", "-a", "-m", "Bump to #{tag}", tag) if options[:tag]
137
172
  end
138
173
 
139
174
  def git_add(file)
@@ -220,31 +255,6 @@ module Bump
220
255
  end
221
256
  end
222
257
 
223
- def next_version(current, part)
224
- current, prerelease = current.split('-')
225
- major, minor, patch, *other = current.split('.')
226
- case part
227
- when "major"
228
- major = major.succ
229
- minor = 0
230
- patch = 0
231
- prerelease = nil
232
- when "minor"
233
- minor = minor.succ
234
- patch = 0
235
- prerelease = nil
236
- when "patch"
237
- patch = patch.succ
238
- when "pre"
239
- prerelease.strip! if prerelease.respond_to? :strip
240
- prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
241
- else
242
- raise "unknown part #{part.inspect}"
243
- end
244
- version = [major, minor, patch, *other].compact.join('.')
245
- [version, prerelease].compact.join('-')
246
- end
247
-
248
258
  def under_version_control?(file)
249
259
  @all_files ||= `git ls-files`.split(/\r?\n/)
250
260
  @all_files.include?(file)
@@ -7,9 +7,11 @@ namespace :bump do
7
7
  abort unless status == 0
8
8
  end
9
9
 
10
- (Bump::Bump::BUMPS + ["current", "file"]).each do |bump|
10
+ (Bump::Bump::BUMPS + ["current", "file", "show-next"]).each do |bump|
11
11
  if bump == "current"
12
12
  desc "Show current gem version"
13
+ elsif bump == "show-next"
14
+ desc "Show next #{Bump::Bump::BUMPS.join('|')} version."
13
15
  elsif bump == "file"
14
16
  desc "Show version file path"
15
17
  else
@@ -25,8 +27,10 @@ namespace :bump do
25
27
  end
26
28
  options = {
27
29
  tag: ENV['TAG'],
30
+ tag_prefix: ENV['TAG_PREFIX'],
28
31
  commit: ENV['COMMIT'],
29
- bundle: ENV['BUNDLE']
32
+ bundle: ENV['BUNDLE'],
33
+ increment: ENV['INCREMENT']
30
34
  }
31
35
  run_bump.call(bump, Bump::Bump.parse_cli_options!(options))
32
36
  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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Marcilhacy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler