git-version-bump 0.18.0 → 0.18.0.8.g580160f
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +33 -0
- data/git-version-bump.gemspec +1 -1
- data/lib/git-version-bump/version.rb +31 -6
- data/lib/git-version-bump.rb +98 -105
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63fc7b28285b00549b449412a047a9abfddcde7f3306c8fd17285b97616c51d3
|
4
|
+
data.tar.gz: 8bc1c9a5e33b285602f28f49d24e16ab747b9e9556bc239c364f5236fbb733c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b986ba7470d40aee830db38aceb0581e23ee53e122371101b5625a90053d2df73c7d466329c5eb8070f07fc959b4dc966d013a72572fc9434d6d6afa0c482529
|
7
|
+
data.tar.gz: 981aac0343a8c43810dbc1725c68f192eef26706bab0f6e59cda1383fa17167e9e0c26e78d57c9efd738501a795fa5b36914ba5fc1e01b35ded8a8b8116c377c
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: "Release to RubyGems"
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branch: [main]
|
5
|
+
release:
|
6
|
+
types: [created]
|
7
|
+
workflow_dispatch:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
upload:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
name: "Upload gem"
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
with:
|
17
|
+
fetch-depth: 0
|
18
|
+
|
19
|
+
- name: Install ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: '2.7'
|
23
|
+
bundler-cache: true
|
24
|
+
|
25
|
+
- name: Workaround for https://github.com/actions/checkout/issues/290
|
26
|
+
run: |
|
27
|
+
git fetch --force --tags
|
28
|
+
|
29
|
+
- name: Do The Needful
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
32
|
+
run: |
|
33
|
+
bundle exec rake release:rubygem_push
|
data/git-version-bump.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.platform = Gem::Platform::RUBY
|
12
12
|
s.required_ruby_version = ">= 2.1.0"
|
13
13
|
|
14
|
-
s.homepage = "
|
14
|
+
s.homepage = "https://github.com/mpalmer/git-version-bump"
|
15
15
|
s.summary = "Manage your app version entirely via git tags"
|
16
16
|
s.authors = ["Matt Palmer"]
|
17
17
|
|
@@ -1,8 +1,33 @@
|
|
1
1
|
module GitVersionBump
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
def self.VERSION
|
3
|
+
GVB.version
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.MAJOR_VERSION
|
7
|
+
GVB.major_version
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.MINOR_VERSION
|
11
|
+
GVB.minor_version
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.PATCH_VERSION
|
15
|
+
GVB.patch_version
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.INTERNAL_REVISION
|
19
|
+
GVB.internal_revision
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.DATE
|
23
|
+
GVB.date
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.const_missing(c)
|
27
|
+
if self.respond_to?(c) && c =~ /\A[A-Z_]+\z/
|
28
|
+
public_send c
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
8
33
|
end
|
data/lib/git-version-bump.rb
CHANGED
@@ -15,34 +15,21 @@ module GitVersionBump
|
|
15
15
|
end
|
16
16
|
|
17
17
|
VERSION_TAG_GLOB = 'v[0-9]*.[0-9]*.*[0-9]'
|
18
|
+
private_constant :VERSION_TAG_GLOB
|
18
19
|
|
19
20
|
DEVNULL = Gem.win_platform? ? "NUL" : "/dev/null"
|
21
|
+
private_constant :DEVNULL
|
20
22
|
|
21
|
-
def self.version(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
run_command(git_cmd, "getting current version descriptor").
|
27
|
-
strip.
|
28
|
-
gsub(/^v/, '').
|
29
|
-
gsub('-', '.')
|
30
|
-
rescue CommandFailure
|
31
|
-
# git failed us; we're either not in a git repo or else we've never
|
32
|
-
# tagged anything before.
|
33
|
-
|
34
|
-
# Are we in a git repo with no tags? If so, try to use the gemspec
|
35
|
-
# and if that fails then abort
|
36
|
-
begin
|
37
|
-
gem_version(use_local_git)
|
38
|
-
rescue VersionUnobtainable
|
39
|
-
"0.0.0.1.ENOTAG"
|
40
|
-
end
|
23
|
+
def self.version(use_local_dir=false, include_lite_tags=false)
|
24
|
+
if use_local_dir
|
25
|
+
repo_version(true, include_lite_tags)
|
26
|
+
else
|
27
|
+
gem_version || repo_version(false, include_lite_tags)
|
41
28
|
end
|
42
29
|
end
|
43
30
|
|
44
|
-
def self.major_version(
|
45
|
-
ver = version(
|
31
|
+
def self.major_version(use_local_dir=false, include_lite_tags=false)
|
32
|
+
ver = version(use_local_dir, include_lite_tags)
|
46
33
|
v = ver.split('.')[0]
|
47
34
|
|
48
35
|
unless v =~ /^[0-9]+$/
|
@@ -53,8 +40,8 @@ module GitVersionBump
|
|
53
40
|
return v.to_i
|
54
41
|
end
|
55
42
|
|
56
|
-
def self.minor_version(
|
57
|
-
ver = version(
|
43
|
+
def self.minor_version(use_local_dir=false, include_lite_tags=false)
|
44
|
+
ver = version(use_local_dir, include_lite_tags)
|
58
45
|
v = ver.split('.')[1]
|
59
46
|
|
60
47
|
unless v =~ /^[0-9]+$/
|
@@ -65,8 +52,8 @@ module GitVersionBump
|
|
65
52
|
return v.to_i
|
66
53
|
end
|
67
54
|
|
68
|
-
def self.patch_version(
|
69
|
-
ver = version(
|
55
|
+
def self.patch_version(use_local_dir=false, include_lite_tags=false)
|
56
|
+
ver = version(use_local_dir, include_lite_tags)
|
70
57
|
v = ver.split('.')[2]
|
71
58
|
|
72
59
|
unless v =~ /^[0-9]+$/
|
@@ -77,34 +64,15 @@ module GitVersionBump
|
|
77
64
|
return v.to_i
|
78
65
|
end
|
79
66
|
|
80
|
-
def self.internal_revision(
|
81
|
-
version(
|
67
|
+
def self.internal_revision(use_local_dir=false, include_lite_tags=false)
|
68
|
+
version(use_local_dir, include_lite_tags).split('.', 4)[3].to_s
|
82
69
|
end
|
83
70
|
|
84
|
-
def self.date(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if dirty_tree?(git_dir(use_local_git))
|
90
|
-
Time.now.strftime("%F")
|
91
|
-
else
|
92
|
-
# Clean tree. Date of last commit is needed.
|
93
|
-
(run_command(["git", "-C", git_dir(use_local_git), "show", "--no-show-signature", "--format=format:%cd", "--date=short"], "getting date of last commit").lines.first || "").strip
|
94
|
-
end
|
95
|
-
rescue CommandFailure
|
96
|
-
# Presumably not in a git tree
|
97
|
-
if use_local_git
|
98
|
-
raise RuntimeError,
|
99
|
-
"GVB.date(use_local_git=true) called from non-git location"
|
100
|
-
end
|
101
|
-
|
102
|
-
if spec = caller_gemspec
|
103
|
-
spec.date.strftime("%F")
|
104
|
-
else
|
105
|
-
raise RuntimeError,
|
106
|
-
"GVB.date called from mysterious, non-gem location."
|
107
|
-
end
|
71
|
+
def self.date(use_local_dir=false, include_lite_tags = false)
|
72
|
+
if use_local_dir
|
73
|
+
repo_date(true, include_lite_tags)
|
74
|
+
else
|
75
|
+
gem_date || repo_date(false, include_lite_tags)
|
108
76
|
end
|
109
77
|
end
|
110
78
|
|
@@ -186,46 +154,47 @@ module GitVersionBump
|
|
186
154
|
# version. Since hashes are hex, we're boned. Sorry about that. Don't
|
187
155
|
# make builds off a branch, basically.
|
188
156
|
#
|
189
|
-
def self.commit_date_version(
|
190
|
-
|
157
|
+
def self.commit_date_version(use_local_dir = false)
|
158
|
+
if use_local_dir
|
159
|
+
commit_date_version_string(true)
|
160
|
+
else
|
161
|
+
gem_version || commit_date_version_string(false)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.commit_date_version_string(use_local_dir = false)
|
166
|
+
commit_dates = run_command(["git", "-C", git_dir(use_local_dir).to_s, "log", "--no-show-signature", "--format=%at"], "getting dates of all commits").
|
191
167
|
split("\n").
|
192
168
|
map { |l| Time.at(Integer(l)).strftime("%Y%m%d") }
|
193
169
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
else
|
201
|
-
""
|
202
|
-
end
|
203
|
-
|
204
|
-
return "0.#{version_date}.#{commit_count}#{dirty_suffix}"
|
170
|
+
version_date = commit_dates.first
|
171
|
+
commit_count = commit_dates.select { |d| d == version_date }.length - 1
|
172
|
+
dirty_suffix = if dirty_tree?
|
173
|
+
".dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}"
|
174
|
+
else
|
175
|
+
""
|
205
176
|
end
|
206
177
|
|
207
|
-
#
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
# and if that fails then abort
|
212
|
-
begin
|
213
|
-
return gem_version(use_local_git)
|
214
|
-
rescue VersionUnobtainable
|
178
|
+
return "0.#{version_date}.#{commit_count}#{dirty_suffix}"
|
179
|
+
rescue CommandFailure => ex
|
180
|
+
p :GVB_CDVS_CMD_FAIL, ex.output if debug?
|
181
|
+
if ex.output =~ /fatal: your current branch .* does not have any commits yet/
|
215
182
|
return "0.0.0.1.ENOCOMMITS"
|
183
|
+
else
|
184
|
+
raise VersionUnobtainable, "Could not get commit date-based version from git repository at #{git_dir(use_local_dir)}"
|
216
185
|
end
|
217
186
|
end
|
218
187
|
|
219
|
-
private
|
220
|
-
|
221
188
|
def self.git_available?
|
222
189
|
try_command(["git", "--version"])
|
223
190
|
end
|
191
|
+
private_class_method :git_available?
|
224
192
|
|
225
193
|
def self.dirty_tree?(dir='.')
|
226
194
|
# Are we in a dirty, dirty tree?
|
227
|
-
! run_command(["git", "-C", dir, "status", "--porcelain"], "checking for tree cleanliness").empty?
|
195
|
+
! run_command(["git", "-C", dir.to_s, "status", "--porcelain"], "checking for tree cleanliness").empty?
|
228
196
|
end
|
197
|
+
private_class_method :dirty_tree?
|
229
198
|
|
230
199
|
# Execute a command, specified as an array.
|
231
200
|
#
|
@@ -245,7 +214,7 @@ module GitVersionBump
|
|
245
214
|
p :GVB_CMD, desc, cmd
|
246
215
|
end
|
247
216
|
|
248
|
-
out, status = Open3.capture2e(*cmd)
|
217
|
+
out, status = Open3.capture2e({"LC_MESSAGES" => "C"}, *cmd)
|
249
218
|
|
250
219
|
if status.exitstatus != 0
|
251
220
|
raise CommandFailure.new("Failed while #{desc}", out, status.exitstatus)
|
@@ -253,6 +222,7 @@ module GitVersionBump
|
|
253
222
|
out
|
254
223
|
end
|
255
224
|
end
|
225
|
+
private_class_method :run_command
|
256
226
|
|
257
227
|
# Execute a command, and return whether it succeeded or failed.
|
258
228
|
#
|
@@ -264,6 +234,7 @@ module GitVersionBump
|
|
264
234
|
false
|
265
235
|
end
|
266
236
|
end
|
237
|
+
private_class_method :try_command
|
267
238
|
|
268
239
|
def self.caller_file
|
269
240
|
# Who called us? Because this method gets called from other methods
|
@@ -275,8 +246,9 @@ module GitVersionBump
|
|
275
246
|
map(&:path).
|
276
247
|
tap { |c| p :CALLER_LOCATIONS, c if debug? }.
|
277
248
|
find { |l| l != __FILE__ }
|
278
|
-
).realpath
|
249
|
+
).realpath rescue nil
|
279
250
|
end
|
251
|
+
private_class_method :caller_file
|
280
252
|
|
281
253
|
def self.caller_gemspec
|
282
254
|
cf = caller_file or return nil
|
@@ -302,54 +274,75 @@ module GitVersionBump
|
|
302
274
|
end
|
303
275
|
end.compact!
|
304
276
|
|
305
|
-
if search_dirs.find { |d| cf.index(d) == 0 }
|
277
|
+
if search_dirs.find { |d| cf.to_s.index(d) == 0 }
|
306
278
|
return spec
|
307
279
|
end
|
308
280
|
end
|
309
281
|
|
310
|
-
|
311
|
-
|
282
|
+
if debug?
|
283
|
+
p :GVB_NO_GEMSPEC, cf
|
284
|
+
end
|
285
|
+
|
286
|
+
nil
|
312
287
|
end
|
288
|
+
private_class_method :caller_gemspec
|
313
289
|
|
314
|
-
def self.gem_version
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
290
|
+
def self.gem_version
|
291
|
+
caller_gemspec&.version&.to_s
|
292
|
+
end
|
293
|
+
private_class_method :gem_version
|
319
294
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
295
|
+
def self.gem_date
|
296
|
+
caller_gemspec&.date&.strftime("%F")
|
297
|
+
end
|
298
|
+
private_class_method :gem_version
|
299
|
+
|
300
|
+
def self.repo_version(use_local_dir, include_lite_tags)
|
301
|
+
git_cmd = ["git", "-C", git_dir(use_local_dir).to_s, "describe", "--dirty=.1.dirty.#{Time.now.strftime("%Y%m%d.%H%M%S")}", "--match=#{VERSION_TAG_GLOB}"]
|
302
|
+
git_cmd << "--tags" if include_lite_tags
|
303
|
+
|
304
|
+
begin
|
305
|
+
run_command(git_cmd, "getting current version descriptor").
|
306
|
+
strip.
|
307
|
+
gsub(/^v/, '').
|
308
|
+
gsub('-', '.')
|
309
|
+
rescue CommandFailure => ex
|
310
|
+
p :GVB_REPO_VERSION_FAILURE, ex.output if debug?
|
311
|
+
if ex.output =~ /fatal: No names found, cannot describe anything/
|
312
|
+
# aka "no tags, bro"
|
313
|
+
"0.0.0.1.ENOTAG"
|
329
314
|
else
|
330
|
-
raise VersionUnobtainable,
|
331
|
-
"GVB.version(#{use_local_git.inspect}) failed; perhaps you need to install git?"
|
315
|
+
raise VersionUnobtainable, "Could not get version from gemspec or git repository at #{git_dir(use_local_dir)}"
|
332
316
|
end
|
333
317
|
end
|
334
318
|
end
|
319
|
+
private_class_method :repo_version
|
335
320
|
|
336
|
-
def self.
|
337
|
-
if
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
321
|
+
def self.repo_date(use_local_dir, include_lite_tags)
|
322
|
+
if dirty_tree?(git_dir(use_local_dir))
|
323
|
+
Time.now.strftime("%F")
|
324
|
+
else
|
325
|
+
# Clean tree. Date of last commit is needed.
|
326
|
+
(run_command(["git", "-C", git_dir(use_local_dir).to_s, "show", "--no-show-signature", "--format=format:%cd", "--date=short"], "getting date of last commit").lines.first || "").strip
|
327
|
+
end
|
328
|
+
rescue CommandFailure
|
329
|
+
raise VersionUnobtainable, "Could not get commit date from git repository at #{git_dir(use_local_dir)}"
|
330
|
+
end
|
331
|
+
private_class_method :repo_date
|
342
332
|
|
333
|
+
def self.git_dir(use_local_dir = false)
|
334
|
+
if use_local_dir
|
343
335
|
Dir.pwd
|
344
336
|
else
|
345
|
-
|
346
|
-
end.tap { |d| p :GVB_GIT_DIR,
|
337
|
+
caller_file&.dirname || Dir.pwd
|
338
|
+
end.tap { |d| p :GVB_GIT_DIR, use_local_dir, d if debug? }
|
347
339
|
end
|
348
340
|
private_class_method :git_dir
|
349
341
|
|
350
342
|
def self.debug?
|
351
343
|
ENV.key?("GVB_DEBUG")
|
352
344
|
end
|
345
|
+
private_class_method :debug?
|
353
346
|
end
|
354
347
|
|
355
348
|
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.18.0
|
4
|
+
version: 0.18.0.8.g580160f
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github-release
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.md
|
76
76
|
files:
|
77
|
+
- ".github/workflows/release.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- Gemfile
|
79
80
|
- LICENCE
|
@@ -84,7 +85,7 @@ files:
|
|
84
85
|
- lib/git-version-bump.rb
|
85
86
|
- lib/git-version-bump/rake-tasks.rb
|
86
87
|
- lib/git-version-bump/version.rb
|
87
|
-
homepage:
|
88
|
+
homepage: https://github.com/mpalmer/git-version-bump
|
88
89
|
licenses: []
|
89
90
|
metadata: {}
|
90
91
|
post_install_message:
|
@@ -98,11 +99,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: 2.1.0
|
99
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
101
|
requirements:
|
101
|
-
- - "
|
102
|
+
- - ">"
|
102
103
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
104
|
+
version: 1.3.1
|
104
105
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.1.6
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: Manage your app version entirely via git tags
|