bump 0.6.1 → 0.7.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 +4 -4
  2. data/README.md +8 -0
  3. data/bin/bump +16 -17
  4. data/lib/bump.rb +64 -29
  5. data/lib/bump/tasks.rb +7 -3
  6. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1667a11fae813507f2b4f6a105774f96f9a28a2d
4
- data.tar.gz: bdc45d4d01fe2753c5711e39c516170abda8740f
3
+ metadata.gz: 17af1c7f47a19abd1ace6aee8345088421e47453
4
+ data.tar.gz: ab54a763ebe1126c7b0322b70373818fa89620cb
5
5
  SHA512:
6
- metadata.gz: 672a2823801f52f781f06d677ec8d7e53318bdf766675b674707e9c2288be6066b4912b122f3dc4824e15fc96ae4f8e1245545be92876168b1c7d47fdd25cb40
7
- data.tar.gz: bce54abe9b989efa56252c060aae3ffcf0c543a2e40149d5bce9df4ff2fbadddfd3d41b5548f5d5c7ee52aea0dda8e4202d25f795105964677e3a10b34c12b85
6
+ metadata.gz: bba34c35004146cb1a70caa0393755f983dab7ea2008fb540297a48ce6f06054e5ff4b2db6c4022c3e563494ba60224a3d856aec27a9763ecf01bf163de2e6f8
7
+ data.tar.gz: 07c299ca4ee9e13c0b7d35f65119dbd93dc55fac9d68f53b6351e89f6e74dff09c48a568679295c780768b64177ae68b3805bba65ceee4dc4650c40a69ffe5b9
data/README.md CHANGED
@@ -49,6 +49,12 @@ If you don't want to run the `bundle` command after bumping, add the `--no-bundl
49
49
 
50
50
  bump patch --no-bundle
51
51
 
52
+ ### `--replace-in`
53
+
54
+ If you want to bump the version in additional files
55
+
56
+ bump patch --reaplace-in Readme.md
57
+
52
58
  ### `--commit-message [MSG], -m [MSG]`
53
59
 
54
60
  If you want to append additional information to the commit message, pass it in using the `--commit-message [MSG]` or `-m [MSG]` option.
@@ -69,6 +75,8 @@ require "bump/tasks"
69
75
  # if you want to always tag the version, add:
70
76
  # Bump.tag_by_default = true
71
77
  #
78
+ # if you want to bump the version in additional files, add:
79
+ # Bump.replace_in_default = ["Readme.md"]
72
80
 
73
81
  ```
74
82
 
data/bin/bump CHANGED
@@ -3,25 +3,26 @@ require 'optparse'
3
3
 
4
4
  options = {}
5
5
  OptionParser.new do |opts|
6
- opts.banner = <<BANNER
7
- Bump your gem version.
6
+ opts.banner = <<-BANNER.gsub(/^ /, "")
7
+ Bump your gem version.
8
8
 
9
- 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
9
+ 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
17
17
 
18
- Options:
19
- BANNER
18
+ Options:
19
+ BANNER
20
20
  opts.on("--no-commit", "Do not make a commit.") { options[:commit] = false }
21
- opts.on("-m","--commit-message [MSG]", "Append MSG to the commit message.") {|msg| options[:commit_message] = msg }
21
+ opts.on("-m", "--commit-message MSG", String, "Append MSG to the commit message.") { |msg| options[:commit_message] = msg }
22
22
  opts.on("--no-bundle", "Do not bundle.") { options[:bundle] = false }
23
23
  opts.on("--tag", "Create git tag from version (only if commit is true).") { options[:tag] = true }
24
- opts.on("-h", "--help","Show this.") { puts opts; exit }
24
+ opts.on("--replace-in FILE", String, "Replace old version with the new version additionally in this file") { |f| (options[:replace_in] ||= []) << f }
25
+ opts.on("-h", "--help", "Show this.") { puts opts; exit }
25
26
  end.parse!
26
27
 
27
28
  unless (ARGV.size == 1 && ARGV.first != "set") || (ARGV.size == 2 && ARGV.first == "set")
@@ -29,9 +30,7 @@ unless (ARGV.size == 1 && ARGV.first != "set") || (ARGV.size == 2 && ARGV.first
29
30
  exit 1
30
31
  end
31
32
 
32
- if ARGV.first == "set"
33
- options[:version] = ARGV[1]
34
- end
33
+ options[:version] = ARGV[1] if ARGV[0] == "set"
35
34
 
36
35
  require File.dirname(__FILE__) + '/../lib/bump'
37
36
  output, status = Bump::Bump.run(ARGV.first, options)
@@ -7,33 +7,35 @@ module Bump
7
7
  class RakeArgumentsDeprecatedError < StandardError; end
8
8
 
9
9
  class <<self
10
- attr_accessor :tag_by_default
10
+ attr_accessor :tag_by_default, :replace_in_default
11
11
  end
12
12
 
13
13
  class Bump
14
- BUMPS = %w(major minor patch pre)
15
- PRERELEASE = ["alpha","beta","rc",nil]
14
+ BUMPS = ["major", "minor", "patch", "pre"].freeze
15
+ PRERELEASE = ["alpha", "beta", "rc", nil].freeze
16
16
  OPTIONS = BUMPS | ["set", "current", "file"]
17
- VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/
17
+ VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/.freeze
18
18
 
19
19
  class << self
20
-
21
20
  def defaults
22
21
  {
23
- :tag => ::Bump.tag_by_default,
24
- :commit => true,
25
- :bundle => File.exist?("Gemfile")
22
+ tag: ::Bump.tag_by_default,
23
+ commit: true,
24
+ bundle: File.exist?("Gemfile"),
25
+ replace_in: ::Bump.replace_in_default || []
26
26
  }
27
27
  end
28
28
 
29
- def run(bump, options={})
29
+ def run(bump, options = {})
30
30
  options = defaults.merge(options)
31
+ options[:commit] = false unless File.directory?(".git")
31
32
 
32
33
  case bump
33
34
  when *BUMPS
34
35
  bump_part(bump, options)
35
36
  when "set"
36
37
  raise InvalidVersionError unless options[:version]
38
+
37
39
  bump_set(options[:version], options)
38
40
  when "current"
39
41
  ["Current version: #{current}", 0]
@@ -66,7 +68,7 @@ module Bump
66
68
  options.each do |key, value|
67
69
  options[key] = parse_cli_options_value(value)
68
70
  end
69
- options.delete_if{|key, value| value.nil?}
71
+ options.delete_if { |_key, value| value.nil? }
70
72
  end
71
73
 
72
74
  private
@@ -82,13 +84,26 @@ module Bump
82
84
  end
83
85
 
84
86
  def bump(file, current, next_version, options)
85
- replace(file, current, next_version)
86
- if options[:bundle] and Dir.glob('*.gemspec').any? and under_version_control?("Gemfile.lock")
87
+ # bump in files that need to change
88
+ [file, *options[:replace_in]].each do |f|
89
+ return ["Unable to find version #{current} in #{f}", 1] unless replace f, current, next_version
90
+
91
+ git_add f if options[:commit]
92
+ end
93
+
94
+ # bundle if needed
95
+ if options[:bundle] && Dir.glob('*.gemspec').any? && under_version_control?("Gemfile.lock")
87
96
  bundler_with_clean_env do
88
97
  return ["Bundle error", 1] unless system("bundle")
98
+
99
+ git_add "Gemfile.lock" if options[:commit]
89
100
  end
90
101
  end
91
- commit(next_version, file, options) if options[:commit]
102
+
103
+ # commit staged changes
104
+ commit next_version, options if options[:commit]
105
+
106
+ # tell user the result
92
107
  ["Bump version #{current} to #{next_version}", 0]
93
108
  end
94
109
 
@@ -112,19 +127,24 @@ module Bump
112
127
  end
113
128
 
114
129
  def commit_message(version, options)
115
- (options[:commit_message]) ? "v#{version} #{options[:commit_message]}" : "v#{version}"
130
+ base = "v#{version}"
131
+ options[:commit_message] ? "#{base} #{options[:commit_message]}" : base
132
+ end
133
+
134
+ def commit(version, options)
135
+ system("git", "commit", "-m", commit_message(version, options))
136
+ system("git", "tag", "-a", "-m", "Bump to v#{version}", "v#{version}") if options[:tag]
116
137
  end
117
138
 
118
- def commit(version, file, options)
119
- return unless File.directory?(".git")
120
- system("git add --update Gemfile.lock") if options[:bundle]
121
- system("git add --update #{file} && git commit -m '#{commit_message(version, options)}'")
122
- system("git tag -a -m 'Bump to v#{version}' v#{version}") if options[:tag]
139
+ def git_add(file)
140
+ system("git", "add", "--update", file)
123
141
  end
124
142
 
125
143
  def replace(file, old, new)
126
144
  content = File.read(file)
127
- File.open(file, "w"){|f| f.write(content.sub(old, new)) }
145
+ return unless content.sub!(old, new)
146
+
147
+ File.write(file, content)
128
148
  end
129
149
 
130
150
  def current_info
@@ -132,18 +152,25 @@ module Bump
132
152
  version_from_version ||
133
153
  version_from_version_rb ||
134
154
  version_from_gemspec ||
135
- version_from_lib_rb ||
136
- version_from_chef ||
155
+ version_from_lib_rb ||
156
+ version_from_chef ||
137
157
  raise(UnfoundVersionFileError)
138
158
  )
139
159
  raise UnfoundVersionError unless version
160
+
140
161
  [version, file]
141
162
  end
142
163
 
143
164
  def version_from_gemspec
144
- return unless file = find_version_file("*.gemspec")
145
- version = File.read(file)[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1]
146
- return unless version = File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1] if version.nil?
165
+ return unless file = find_version_file("*.gemspec")
166
+
167
+ content = File.read(file)
168
+ version = (
169
+ content[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1] ||
170
+ File.read(file)[/Gem::Specification.new.+ ["']#{VERSION_REGEX}["']/, 1]
171
+ )
172
+ return unless version
173
+
147
174
  [version, file]
148
175
  end
149
176
 
@@ -158,6 +185,7 @@ module Bump
158
185
 
159
186
  def version_from_version
160
187
  return unless file = find_version_file("VERSION")
188
+
161
189
  extract_version_from_file(file)
162
190
  end
163
191
 
@@ -166,17 +194,19 @@ module Bump
166
194
  file = files.detect do |f|
167
195
  File.read(f) =~ /^\s+VERSION = ['"](#{VERSION_REGEX})['"]/i
168
196
  end
169
- [$1, file] if file
197
+ [Regexp.last_match(1), file] if file
170
198
  end
171
199
 
172
200
  def version_from_chef
173
201
  file = find_version_file("metadata.rb")
174
202
  return unless file && File.read(file) =~ /^version\s+(['"])(#{VERSION_REGEX})['"]/
175
- [$2, file]
203
+
204
+ [Regexp.last_match(2), file]
176
205
  end
177
206
 
178
207
  def extract_version_from_file(file)
179
208
  return unless version = File.read(file)[VERSION_REGEX]
209
+
180
210
  [version, file]
181
211
  end
182
212
 
@@ -195,9 +225,14 @@ module Bump
195
225
  major, minor, patch, *other = current.split('.')
196
226
  case part
197
227
  when "major"
198
- major, minor, patch, prerelease = major.succ, 0, 0, nil
228
+ major = major.succ
229
+ minor = 0
230
+ patch = 0
231
+ prerelease = nil
199
232
  when "minor"
200
- minor, patch, prerelease = minor.succ, 0, nil
233
+ minor = minor.succ
234
+ patch = 0
235
+ prerelease = nil
201
236
  when "patch"
202
237
  patch = patch.succ
203
238
  when "pre"
@@ -17,8 +17,12 @@ namespace :bump do
17
17
  end
18
18
 
19
19
  task bump, :tag do |_task, args|
20
- raise RakeArgumentsDeprecatedError,
21
- "rake arguments are deprecated, use TAG=false to disable tagging" if args.tag
20
+ if args.tag
21
+ raise(
22
+ RakeArgumentsDeprecatedError,
23
+ "rake arguments are deprecated, use TAG=false to disable tagging"
24
+ )
25
+ end
22
26
  options = {
23
27
  tag: ENV['TAG'],
24
28
  commit: ENV['COMMIT'],
@@ -30,6 +34,6 @@ namespace :bump do
30
34
 
31
35
  desc "Sets the version number using the VERSION environment variable"
32
36
  task :set do
33
- run_bump.call("set", :version => ENV['VERSION'])
37
+ run_bump.call("set", version: ENV['VERSION'])
34
38
  end
35
39
  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.1
4
+ version: 0.7.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-06-07 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
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'
55
69
  description:
56
70
  email: g.marcilhacy@gmail.com
57
71
  executables:
@@ -75,7 +89,7 @@ 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.2.0
79
93
  required_rubygems_version: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - ">="