git-version-bump 0.14.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +16 -2
- data/bin/git-version-bump +17 -7
- data/git-version-bump.gemspec +5 -2
- data/lib/git-version-bump.rb +74 -45
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '084e552015ea8de36e92598ea4ec4de57916b0cdf0ba9ee8c8ff7974da9df8ff'
|
4
|
+
data.tar.gz: e361b6214097aa2e9cf4a30e993cb4ad9dc9c5f3283ae6d39d219e28f684f8fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e168a05d6349ecc3b69bf09eff3d1ddd28253dde4c69b4ee007257de73af6a7b195dc9e1186d7fca9106dfa40c88680f02139fcc808fb5a2906e8da3b09c534
|
7
|
+
data.tar.gz: 4e295c50077e23342b48c4a9dbfad2a356be4c0d33a5489f365812309c1fa90cd45b3c50197f8ab94b5a8b9fc70aa0771363ed933ffb44e4bee3cbd85b2a7457
|
data/README.md
CHANGED
@@ -99,7 +99,7 @@ gemspec, like this:
|
|
99
99
|
Gem::Specification.new do |s|
|
100
100
|
s.version = GVB.version
|
101
101
|
s.date = GVB.date
|
102
|
-
|
102
|
+
|
103
103
|
...
|
104
104
|
end
|
105
105
|
|
@@ -118,7 +118,7 @@ what version of a library you're running, then you probably like to define a
|
|
118
118
|
to do:
|
119
119
|
|
120
120
|
require 'git-version-bump'
|
121
|
-
|
121
|
+
|
122
122
|
class Foobar
|
123
123
|
VERSION = GVB.version
|
124
124
|
end
|
@@ -126,6 +126,20 @@ to do:
|
|
126
126
|
This will work correctly inside your git tree, and also in your installed
|
127
127
|
gem. Magical!
|
128
128
|
|
129
|
+
#### For projects using lite tags
|
130
|
+
|
131
|
+
If you are using GitHub releases for your project or some other method that
|
132
|
+
involves light tags (tags with no annotations), you might notice that these
|
133
|
+
tags are not detected by git-version-bump by default. If you want these
|
134
|
+
commits to be detected then use the following configuration:
|
135
|
+
|
136
|
+
require 'git-version-bump'
|
137
|
+
|
138
|
+
class Foobar
|
139
|
+
# First parameter is use_local_git, second is include_lite_tags
|
140
|
+
VERSION = GVB.version(false, true)
|
141
|
+
end
|
142
|
+
|
129
143
|
|
130
144
|
# Contributing
|
131
145
|
|
data/bin/git-version-bump
CHANGED
@@ -4,10 +4,11 @@ require 'git-version-bump'
|
|
4
4
|
|
5
5
|
if ARGV[0].nil? or
|
6
6
|
ARGV[0].empty? or
|
7
|
+
(ARGV.length == 1 && (ARGV[0] == "-d" || ARGV[0] == "--dry-run")) or
|
7
8
|
ARGV[0] == '-h' or
|
8
9
|
ARGV[0] == '--help'
|
9
10
|
$stderr.puts <<-EOF.gsub(/^\t\t/, '')
|
10
|
-
Usage: git version-bump [-n|--notes] <major|minor|patch|show>
|
11
|
+
Usage: git version-bump [-n|--notes] [-d|--dry-run] <major|minor|patch|show>
|
11
12
|
|
12
13
|
'major': x.y.z -> x+1.0.0
|
13
14
|
'minor': x.y.z -> x.y+1.0
|
@@ -15,11 +16,15 @@ if ARGV[0].nil? or
|
|
15
16
|
|
16
17
|
'show': Display the current GVB version
|
17
18
|
|
18
|
-
--
|
19
|
+
-d, --dry-run: Calculate and return the bump value, but don't update git workspace or remote
|
20
|
+
-n, --notes: Prompt for "release notes" to add to the release tag
|
21
|
+
-l, --lite-tags: Include non-annotated git tags
|
19
22
|
EOF
|
20
23
|
end
|
21
24
|
|
22
25
|
release_notes = ARGV.delete('-n') || ARGV.delete('--notes')
|
26
|
+
dry_run = ARGV.delete('-d') || ARGV.delete('--dry-run')
|
27
|
+
lite_tags = ARGV.delete('-l') || ARGV.delete('--lite-tags')
|
23
28
|
|
24
29
|
if ARGV[0].nil? or ARGV[0].empty?
|
25
30
|
exit 1
|
@@ -27,13 +32,13 @@ elsif ARGV[0] == '-h' or ARGV[0] == '--help'
|
|
27
32
|
exit 0
|
28
33
|
end
|
29
34
|
|
30
|
-
case ARGV[0].downcase
|
35
|
+
result = case ARGV[0].downcase
|
31
36
|
when /^maj?o?r?$/
|
32
|
-
|
37
|
+
"#{GVB.major_version(true) + 1}.0.0"
|
33
38
|
when /^min?o?r?$/
|
34
|
-
|
39
|
+
"#{GVB.major_version(true)}.#{GVB.minor_version(true)+1}.0"
|
35
40
|
when /^pa?t?c?h?$/
|
36
|
-
|
41
|
+
"#{GVB.major_version(true)}.#{GVB.minor_version(true)}.#{GVB.patch_version(true)+1}"
|
37
42
|
when /^sh?o?w?$/
|
38
43
|
puts GVB.version(true)
|
39
44
|
exit 0
|
@@ -42,4 +47,9 @@ case ARGV[0].downcase
|
|
42
47
|
exit 1
|
43
48
|
end
|
44
49
|
|
45
|
-
|
50
|
+
if dry_run
|
51
|
+
puts result
|
52
|
+
else
|
53
|
+
GVB.tag_version result, release_notes, lite_tags
|
54
|
+
puts "Version is now #{GVB.version(true)}."
|
55
|
+
end
|
data/git-version-bump.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'git-version-bump'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = "git-version-bump"
|
@@ -6,7 +8,8 @@ Gem::Specification.new do |s|
|
|
6
8
|
s.version = GVB.version
|
7
9
|
s.date = GVB.date
|
8
10
|
|
9
|
-
s.platform
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.required_ruby_version = ">= 2.1.0"
|
10
13
|
|
11
14
|
s.homepage = "http://theshed.hezmatt.org/git-version-bump"
|
12
15
|
s.summary = "Manage your app version entirely via git tags"
|
data/lib/git-version-bump.rb
CHANGED
@@ -5,20 +5,26 @@ require 'pathname'
|
|
5
5
|
module GitVersionBump
|
6
6
|
class VersionUnobtainable < StandardError; end
|
7
7
|
|
8
|
-
|
8
|
+
VERSION_TAG_GLOB = 'v[0-9]*.[0-9]*.*[0-9]'
|
9
|
+
|
10
|
+
DEVNULL = Gem.win_platform? ? "NUL" : "/dev/null"
|
11
|
+
|
12
|
+
def self.version(use_local_git=false, include_lite_tags=false)
|
9
13
|
if use_local_git
|
10
14
|
unless git_available?
|
11
15
|
raise RuntimeError,
|
12
16
|
"GVB.version(use_local_git=true) called, but git isn't installed"
|
13
17
|
end
|
14
18
|
|
15
|
-
sq_git_dir =
|
19
|
+
sq_git_dir = shell_quoted_string(Dir.pwd)
|
16
20
|
else
|
17
|
-
|
18
|
-
sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
|
21
|
+
sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
|
19
22
|
end
|
20
23
|
|
21
|
-
|
24
|
+
git_cmd = "git -C #{sq_git_dir} describe --dirty='.1.dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}' --match='#{VERSION_TAG_GLOB}'"
|
25
|
+
git_cmd << " --tags" if include_lite_tags
|
26
|
+
|
27
|
+
git_ver = `#{git_cmd} 2> #{DEVNULL}`.
|
22
28
|
strip.
|
23
29
|
gsub(/^v/, '').
|
24
30
|
gsub('-', '.')
|
@@ -30,15 +36,17 @@ module GitVersionBump
|
|
30
36
|
# git failed us; we're either not in a git repo or else we've never
|
31
37
|
# tagged anything before.
|
32
38
|
|
33
|
-
# Are we in a git repo with no tags? If so,
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
# Are we in a git repo with no tags? If so, try to use the gemspec
|
40
|
+
# and if that fails then abort
|
41
|
+
begin
|
42
|
+
return gem_version(use_local_git)
|
43
|
+
rescue VersionUnobtainable
|
44
|
+
return "0.0.0.1.ENOTAG"
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
|
-
def self.major_version(use_local_git=false)
|
41
|
-
ver = version(use_local_git)
|
48
|
+
def self.major_version(use_local_git=false, include_lite_tags=false)
|
49
|
+
ver = version(use_local_git, include_lite_tags)
|
42
50
|
v = ver.split('.')[0]
|
43
51
|
|
44
52
|
unless v =~ /^[0-9]+$/
|
@@ -49,8 +57,8 @@ module GitVersionBump
|
|
49
57
|
return v.to_i
|
50
58
|
end
|
51
59
|
|
52
|
-
def self.minor_version(use_local_git=false)
|
53
|
-
ver = version(use_local_git)
|
60
|
+
def self.minor_version(use_local_git=false, include_lite_tags=false)
|
61
|
+
ver = version(use_local_git, include_lite_tags)
|
54
62
|
v = ver.split('.')[1]
|
55
63
|
|
56
64
|
unless v =~ /^[0-9]+$/
|
@@ -61,8 +69,8 @@ module GitVersionBump
|
|
61
69
|
return v.to_i
|
62
70
|
end
|
63
71
|
|
64
|
-
def self.patch_version(use_local_git=false)
|
65
|
-
ver = version(use_local_git)
|
72
|
+
def self.patch_version(use_local_git=false, include_lite_tags=false)
|
73
|
+
ver = version(use_local_git, include_lite_tags)
|
66
74
|
v = ver.split('.')[2]
|
67
75
|
|
68
76
|
unless v =~ /^[0-9]+$/
|
@@ -73,8 +81,8 @@ module GitVersionBump
|
|
73
81
|
return v.to_i
|
74
82
|
end
|
75
83
|
|
76
|
-
def self.internal_revision(use_local_git=false)
|
77
|
-
version(use_local_git).split('.', 4)[3].to_s
|
84
|
+
def self.internal_revision(use_local_git=false, include_lite_tags=false)
|
85
|
+
version(use_local_git, include_lite_tags).split('.', 4)[3].to_s
|
78
86
|
end
|
79
87
|
|
80
88
|
def self.date(use_local_git=false)
|
@@ -84,22 +92,21 @@ module GitVersionBump
|
|
84
92
|
"GVB.date(use_local_git=true), but git is not installed"
|
85
93
|
end
|
86
94
|
|
87
|
-
sq_git_dir =
|
95
|
+
sq_git_dir = shell_quoted_string(Dir.pwd)
|
88
96
|
else
|
89
|
-
|
90
|
-
sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
|
97
|
+
sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
|
91
98
|
end
|
92
99
|
|
93
100
|
# Are we in a git tree?
|
94
|
-
system("git -C #{sq_git_dir} status
|
101
|
+
system("git -C #{sq_git_dir} status > #{DEVNULL} 2>&1")
|
95
102
|
if $? == 0
|
96
103
|
# Yes, we're in git.
|
97
104
|
|
98
|
-
if dirty_tree?
|
105
|
+
if dirty_tree?(sq_git_dir)
|
99
106
|
return Time.now.strftime("%F")
|
100
107
|
else
|
101
108
|
# Clean tree. Date of last commit is needed.
|
102
|
-
return `git -C #{sq_git_dir} show --format=format:%
|
109
|
+
return (`git -C #{sq_git_dir} show --no-show-signature --format=format:%cd --date=short`.lines.first || "").strip
|
103
110
|
end
|
104
111
|
else
|
105
112
|
if use_local_git
|
@@ -117,14 +124,16 @@ module GitVersionBump
|
|
117
124
|
end
|
118
125
|
end
|
119
126
|
|
120
|
-
def self.tag_version(v, release_notes = false)
|
127
|
+
def self.tag_version(v, release_notes = false, include_lite_tags=false)
|
121
128
|
if dirty_tree?
|
122
129
|
puts "You have uncommitted files. Refusing to tag a dirty tree."
|
123
130
|
else
|
124
131
|
if release_notes
|
125
132
|
# We need to find the tag before this one, so we can list all the commits
|
126
133
|
# between the two. This is not a trivial operation.
|
127
|
-
|
134
|
+
git_cmd = "git describe --match='#{VERSION_TAG_GLOB}' --always"
|
135
|
+
git_cmd << ' --tags' if include_lite_tags
|
136
|
+
prev_tag = `#{git_cmd}`.strip.gsub(/-\d+-g[0-9a-f]+$/, '')
|
128
137
|
|
129
138
|
log_file = Tempfile.new('gvb')
|
130
139
|
|
@@ -139,7 +148,7 @@ module GitVersionBump
|
|
139
148
|
EOF
|
140
149
|
|
141
150
|
log_file.close
|
142
|
-
system("git log --format='# %h %s' #{prev_tag}..HEAD >>#{log_file.path}")
|
151
|
+
system("git log --no-show-signature --format='# %h %s' #{prev_tag}..HEAD >>#{log_file.path}")
|
143
152
|
|
144
153
|
pre_hash = Digest::SHA1.hexdigest(File.read(log_file.path))
|
145
154
|
system("git config -e -f #{log_file.path}")
|
@@ -157,8 +166,8 @@ module GitVersionBump
|
|
157
166
|
system("git tag -a -m 'Version v#{v}' v#{v}")
|
158
167
|
end
|
159
168
|
|
160
|
-
system("git push
|
161
|
-
system("git push --tags
|
169
|
+
system("git push > #{DEVNULL} 2>&1")
|
170
|
+
system("git push --tags > #{DEVNULL} 2>&1")
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
@@ -196,10 +205,9 @@ module GitVersionBump
|
|
196
205
|
"GVB.commit_date_version(use_local_git=true) called, but git isn't installed"
|
197
206
|
end
|
198
207
|
|
199
|
-
sq_git_dir =
|
208
|
+
sq_git_dir = shell_quoted_string(Dir.pwd)
|
200
209
|
else
|
201
|
-
|
202
|
-
sq_git_dir = "'" + (File.dirname(caller_file) rescue nil || Dir.pwd).gsub("'", "'\\''") + "'"
|
210
|
+
sq_git_dir = shell_quoted_string((File.dirname(caller_file) rescue nil || Dir.pwd))
|
203
211
|
end
|
204
212
|
|
205
213
|
commit_dates = `git -C #{sq_git_dir} log --format=%at`.
|
@@ -222,25 +230,26 @@ module GitVersionBump
|
|
222
230
|
# git failed us; either we're not in a git repo or else it's a git
|
223
231
|
# repo that's not got any commits.
|
224
232
|
|
225
|
-
# Are we in a git repo with no
|
226
|
-
#
|
227
|
-
|
228
|
-
|
233
|
+
# Are we in a git repo with no commits? If so, try to use the gemspec
|
234
|
+
# and if that fails then abort
|
235
|
+
begin
|
236
|
+
return gem_version(use_local_git)
|
237
|
+
rescue VersionUnobtainable
|
238
|
+
return "0.0.0.1.ENOCOMMITS"
|
239
|
+
end
|
229
240
|
end
|
230
241
|
|
231
242
|
private
|
232
243
|
|
233
244
|
def self.git_available?
|
234
|
-
system("git --version
|
245
|
+
system("git --version > #{DEVNULL} 2>&1")
|
235
246
|
|
236
247
|
$? == 0
|
237
248
|
end
|
238
249
|
|
239
|
-
def self.dirty_tree?
|
250
|
+
def self.dirty_tree?(sq_git_dir='.')
|
240
251
|
# Are we in a dirty, dirty tree?
|
241
|
-
|
242
|
-
|
243
|
-
$? == 0
|
252
|
+
! `git -C #{sq_git_dir} status --porcelain 2> #{DEVNULL}`.empty?
|
244
253
|
end
|
245
254
|
|
246
255
|
def self.caller_file
|
@@ -249,8 +258,8 @@ module GitVersionBump
|
|
249
258
|
# instead we need to parse the caller stack ourselves to find which
|
250
259
|
# gem we're trying to version all over.
|
251
260
|
Pathname(
|
252
|
-
|
253
|
-
map
|
261
|
+
caller_locations.
|
262
|
+
map(&:path).
|
254
263
|
find { |l| l != __FILE__ }
|
255
264
|
).realpath.to_s rescue nil
|
256
265
|
end
|
@@ -261,8 +270,16 @@ module GitVersionBump
|
|
261
270
|
# Grovel through all the loaded gems to try and find the gem
|
262
271
|
# that contains the caller's file.
|
263
272
|
Gem.loaded_specs.values.each do |spec|
|
264
|
-
|
265
|
-
|
273
|
+
# On Windows I have encountered gems that already have an absolute
|
274
|
+
# path, verify that the path is relative before appending to it
|
275
|
+
search_dirs = spec.require_paths.map do |path|
|
276
|
+
if Pathname(path).absolute?
|
277
|
+
path
|
278
|
+
else
|
279
|
+
File.join(spec.full_gem_path, path)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
search_dirs << File.join(spec.full_gem_path, spec.bindir)
|
266
283
|
search_dirs.map! do |d|
|
267
284
|
begin
|
268
285
|
Pathname(d).realpath.to_s
|
@@ -301,6 +318,18 @@ module GitVersionBump
|
|
301
318
|
end
|
302
319
|
end
|
303
320
|
end
|
321
|
+
|
322
|
+
def self.shell_quoted_string(dir_string)
|
323
|
+
if Gem.win_platform?
|
324
|
+
return "\"#{dir_string}\""
|
325
|
+
else
|
326
|
+
# Shell Quoted, for your convenience
|
327
|
+
return "'#{dir_string.gsub("'", "'\\''")}'"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
private_class_method :shell_quoted_string
|
332
|
+
|
304
333
|
end
|
305
334
|
|
306
335
|
GVB = GitVersionBump unless defined? GVB
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-version-bump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github-release
|
@@ -95,17 +95,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
98
|
+
version: 2.1.0
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
|
106
|
-
rubygems_version: 2.2.2
|
105
|
+
rubygems_version: 3.0.3
|
107
106
|
signing_key:
|
108
107
|
specification_version: 4
|
109
108
|
summary: Manage your app version entirely via git tags
|
110
109
|
test_files: []
|
111
|
-
has_rdoc:
|