bump 0.8.0 → 0.9.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 +40 -23
  3. data/bin/bump +3 -0
  4. data/lib/bump.rb +33 -1
  5. data/lib/bump/tasks.rb +4 -2
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83453453cffa0d63a765fc4fb7aa084d7a992da4
4
- data.tar.gz: f4db814fff42565eee6927dc941b026c282939df
3
+ metadata.gz: 4cc77e3ae46a84602fc8c584624d77b69a44ef4e
4
+ data.tar.gz: a8a1fad7cc8f4f3db749556b81f1c51c168aaaa0
5
5
  SHA512:
6
- metadata.gz: 9e74704154155f9ddb50c45b40a802b6a7a0088e07a7dd073fe1ee11e0580765f1a7add70ababfc247580230a700c3707d4ff75afea36f0bd8dac9c1c11792af
7
- data.tar.gz: 9e892e2d1e59aa12abeab19e5fdff8b54594aa9c8912404d0fd503f64a0628a4601ae81d8fbe63406663e32c3bb6e70fe295234f773b017c0e4fe64e085e5c22
6
+ metadata.gz: e170caed9096057c8826562869cfd62b30b6cb25577b601242e17e3e603d620ddd5f43890cb7e47aa506719d2d198d13c18d581cfeaa21053c75757c3247d575
7
+ data.tar.gz: 48323ff4e45dd6d626781b7251402376c5821cb14f8bcb3ed5b9c8cf198f0af6893c69c3356ff26fdece50e6466e247069022fbcc79db85e71223951595d976a
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
4
+ A gem to bump versions of gems and chef-cookbooks.
5
5
 
6
- Bump is a gem that will simplify the way you build gems and chef-cookbooks.
6
+ - bumps version major / minor / patch / pre
7
+ - bundles
8
+ - commits changes
7
9
 
8
10
  # Installation
9
11
 
@@ -11,35 +13,35 @@ 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
20
  > Current version: 0.1.2
19
21
 
20
- Show next patch version:
22
+ ### Bump (major, minor, patch, pre)
23
+
24
+ bump patch
25
+
26
+ > Bump version 0.1.2 to 0.1.3
27
+
28
+ ### Show next version
21
29
 
22
30
  bump show-next patch
23
31
 
24
32
  > Next patch version: 0.1.3
25
33
 
26
- Version file path:
34
+ ### Show version file path
27
35
 
28
36
  bump file
29
37
 
30
38
  > Version file path: lib/foo/version.rb
31
39
 
32
- Bump (major, minor, patch, pre):
33
-
34
- bump patch
35
-
36
- > Bump version 0.1.2 to 0.1.3
37
-
38
40
  ## Options
39
41
 
40
42
  ### `--no-commit`
41
43
 
42
- If you don't want to make a commit after bumping, add the `--no-commit` option.
44
+ Do not commit after bumping.
43
45
 
44
46
  bump patch --no-commit
45
47
 
@@ -56,39 +58,54 @@ The `--tag-prefix` option can change the tag prefix:
56
58
 
57
59
  ### `--no-bundle`
58
60
 
59
- If you don't want to run the `bundle` command after bumping, add the `--no-bundle` option.
61
+ Do not run `bundle` command after bumping.
60
62
 
61
63
  bump patch --no-bundle
62
64
 
63
65
  ### `--replace-in`
64
66
 
65
- If you want to bump the version in additional files
67
+ Bump the version in additional files.
66
68
 
67
69
  bump patch --reaplace-in Readme.md
68
70
 
69
71
  ### `--commit-message [MSG], -m [MSG]`
70
72
 
71
- If you want to append additional information to the commit message, pass it in using the `--commit-message [MSG]` or `-m [MSG]` option.
73
+ Append additional information to the commit message.
72
74
 
73
- bump patch --commit-message [no-ci]
75
+ bump patch --commit-message "Something extra"
74
76
 
75
77
  or
76
78
 
77
- bump patch -m [no-cli]
79
+ bump patch -m "Something extra"
80
+
81
+ ### `--changelog`
82
+
83
+ Update `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
78
89
 
79
- ### Rake
90
+ ### v0.0.0 - 2019-12-24
91
+ - Added foo
92
+ ```
93
+
94
+ ## Rake
80
95
 
81
96
  ```ruby
82
97
  # Rakefile
83
98
  require "bump/tasks"
84
99
 
85
100
  #
86
- # if you want to always tag the version, add:
87
- # Bump.tag_by_default = true
101
+ # do not always tag the version
102
+ # Bump.tag_by_default = false
88
103
  #
89
- # if you want to bump the version in additional files, add:
104
+ # bump the version in additional files
90
105
  # Bump.replace_in_default = ["Readme.md"]
91
-
106
+ #
107
+ # Maintain changelog:
108
+ # Bump.changelog = true
92
109
  ```
93
110
 
94
111
  rake bump:current # display current version
@@ -107,7 +124,7 @@ require "bump/tasks"
107
124
  rake bump:patch COMMIT=false TAG=false # don't commit, don't tag
108
125
  rake bump:minor BUNDLE=false # don't run `bundle`
109
126
 
110
- ### Ruby
127
+ ## Ruby
111
128
 
112
129
  ```ruby
113
130
  require "bump"
data/bin/bump CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'optparse'
3
5
  require 'shellwords'
4
6
 
@@ -25,6 +27,7 @@ OptionParser.new do |opts|
25
27
  opts.on("--tag", "Create git tag from version (only if commit is true).") { options[:tag] = true }
26
28
  opts.on("--tag-prefix TAG_PREFIX", "Prefix the tag with this string, ex. 'v'") { |tag_prefix| options[:tag_prefix] = tag_prefix }
27
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 }
28
31
  opts.on("-h", "--help", "Show this.") { puts opts; exit }
29
32
  end.parse!
30
33
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bump
2
4
  class InvalidIncrementError < StandardError; end
3
5
  class InvalidOptionError < StandardError; end
@@ -8,7 +10,7 @@ module Bump
8
10
  class RakeArgumentsDeprecatedError < StandardError; end
9
11
 
10
12
  class <<self
11
- attr_accessor :tag_by_default, :replace_in_default
13
+ attr_accessor :tag_by_default, :replace_in_default, :changelog
12
14
  end
13
15
 
14
16
  class Bump
@@ -23,6 +25,7 @@ module Bump
23
25
  tag: ::Bump.tag_by_default,
24
26
  tag_prefix: 'v',
25
27
  commit: true,
28
+ changelog: ::Bump.changelog || false, # TODO: default to true with opt-out once it gets more stable
26
29
  bundle: File.exist?("Gemfile"),
27
30
  replace_in: ::Bump.replace_in_default || []
28
31
  }
@@ -134,6 +137,17 @@ module Bump
134
137
  end
135
138
  end
136
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
+ git_add log if options[:commit]
149
+ end
150
+
137
151
  # commit staged changes
138
152
  commit next_version, options if options[:commit]
139
153
 
@@ -160,6 +174,24 @@ module Bump
160
174
  bump(file, current, next_version, options)
161
175
  end
162
176
 
177
+ def bump_changelog(file, current)
178
+ parts = File.read(file).split(/(^##+.*)/) # headlines and their content
179
+ prev_index = parts.index { |p| p =~ /(^##+.*(\d+\.\d+\.\d+(\.[a-z]+)?).*)/ } # position of previous version
180
+ return "Unable to find previous version" unless prev_index
181
+
182
+ # reuse the same style by just swapping the numbers
183
+ new_heading = "\n" + parts[prev_index].sub($2, current)
184
+
185
+ # add current date if previous heading used that
186
+ new_heading.sub!(/\d\d\d\d-\d\d-\d\d/, Time.now.strftime('%Y-%m-%d'))
187
+
188
+ # put our new heading underneath the "Next" heading, which should be above the last version
189
+ parts.insert prev_index - 1, new_heading
190
+
191
+ File.write file, parts.join("")
192
+ nil
193
+ end
194
+
163
195
  def commit_message(version, options)
164
196
  tag = "#{options[:tag_prefix]}#{version}"
165
197
  options[:commit_message] ? "#{tag} #{options[:commit_message]}" : tag
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bump"
2
4
 
3
5
  namespace :bump do
@@ -18,8 +20,8 @@ namespace :bump do
18
20
  desc "Bump #{bump} part of gem version"
19
21
  end
20
22
 
21
- task bump, :tag do |_task, args|
22
- if args.tag
23
+ task bump, :no_args do |_task, args|
24
+ if args.no_args
23
25
  raise(
24
26
  RakeArgumentsDeprecatedError,
25
27
  "rake arguments are deprecated, use TAG=false to disable tagging"
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.8.0
4
+ version: 0.9.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: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 2.2.0
92
+ version: 2.3.0
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="