raketeer 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -5
- data/Rakefile +2 -0
- data/lib/raketeer.rb +5 -0
- data/lib/raketeer/all.rb +1 -0
- data/lib/raketeer/bump.rb +35 -0
- data/lib/raketeer/bump_task.rb +333 -0
- data/lib/raketeer/bump_ver.rb +144 -0
- data/lib/raketeer/files_bumper.rb +141 -0
- data/lib/raketeer/sem_ver.rb +130 -0
- data/lib/raketeer/util.rb +9 -6
- data/lib/raketeer/version.rb +15 -1
- data/raketeer.gemspec +6 -3
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e6ed3bd0408cc6af232b21a069ea2515d63ea1db1fc40b6d0a1c2e29fa61838
|
4
|
+
data.tar.gz: 46809d4b3d4d65b62a3f4f72fc136b2393727ca871aa0321fefc64cf8cfa62c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffdf10d2f65ca8e0e6d9b8866c1a807749da9aa151c92d44b9f0588478f30b94008f9b100ce709b10f6ef07c1a3fbba43bc74178f0ebcf1c3d46ff8cd157e038
|
7
|
+
data.tar.gz: 4052757cc76e4826759e0f1fc09b664d02ea44b63d00856f9f914ba099c97d5be1eb497e2101ebcb054d71452e31975ed36ef6f4c089b3b640c0cb62ee89ca5b
|
data/CHANGELOG.md
CHANGED
@@ -2,22 +2,36 @@
|
|
2
2
|
|
3
3
|
Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
4
4
|
|
5
|
-
## [[Unreleased]](https://github.com/esotericpig/raketeer/compare/v0.2.
|
5
|
+
## [[Unreleased]](https://github.com/esotericpig/raketeer/compare/v0.2.4...master)
|
6
|
+
|
7
|
+
## [v0.2.4] - 2019-08-02
|
8
|
+
### Added
|
9
|
+
- BumpTask & 'raketeer/bump'
|
10
|
+
- FilesBumper (lib/raketeer/files_bumper.rb)
|
11
|
+
- SemVer (lib/raketeer/sem_ver.rb)
|
12
|
+
- BumpVer (lib/raketeer/bump_ver.rb)
|
13
|
+
- To Util:
|
14
|
+
- to_bool() & TRUE_BOOLS (from my yard_ghurt project)
|
15
|
+
- To version.rb:
|
16
|
+
- DEP_VERSIONS & try_require_dev() (for future use)
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- Util.find_main_executable() to not search for 'bin/*.rb' since almost no project uses an extension in the bin directory
|
6
20
|
|
7
21
|
## [v0.2.3] - 2019-07-30
|
8
22
|
### Fixed
|
9
23
|
- Fixed 'yield' typo in some tasks
|
10
24
|
|
11
25
|
## [v0.2.2] - 2019-07-29
|
12
|
-
### Changed
|
13
|
-
- Refactored some code (minor)
|
14
|
-
- Changed some documentation (minor)
|
15
|
-
|
16
26
|
### Added
|
17
27
|
- RunTask & 'raketeer/run'
|
18
28
|
- Util
|
19
29
|
- bin/raketeer (for testing purposes only, not included in the Gem package)
|
20
30
|
|
31
|
+
### Changed
|
32
|
+
- Refactored some code (minor)
|
33
|
+
- Changed some documentation (minor)
|
34
|
+
|
21
35
|
## [v0.2.1] - 2019-07-24
|
22
36
|
### Changed
|
23
37
|
- Fixed minor/cosmetic typo
|
data/Rakefile
CHANGED
data/lib/raketeer.rb
CHANGED
@@ -21,9 +21,14 @@
|
|
21
21
|
#++
|
22
22
|
|
23
23
|
|
24
|
+
require 'raketeer/bump_task'
|
25
|
+
require 'raketeer/bump_ver'
|
26
|
+
require 'raketeer/files_bumper'
|
24
27
|
require 'raketeer/irb_task'
|
25
28
|
require 'raketeer/nokogiri_install_tasks'
|
26
29
|
require 'raketeer/run_task'
|
30
|
+
require 'raketeer/sem_ver'
|
31
|
+
require 'raketeer/util'
|
27
32
|
require 'raketeer/version'
|
28
33
|
|
29
34
|
###
|
data/lib/raketeer/all.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of Raketeer.
|
7
|
+
# Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# Raketeer is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Raketeer is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU Lesser General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU Lesser General Public License
|
20
|
+
# along with Raketeer. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'raketeer/bump_task'
|
25
|
+
|
26
|
+
module Raketeer
|
27
|
+
###
|
28
|
+
# @author Jonathan Bradley Whited (@esotericpig)
|
29
|
+
# @since 0.2.4
|
30
|
+
###
|
31
|
+
module Bump
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Raketeer::BumpTask.new() # @since 0.2.4
|
@@ -0,0 +1,333 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of Raketeer.
|
7
|
+
# Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# Raketeer is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Raketeer is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU Lesser General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU Lesser General Public License
|
20
|
+
# along with Raketeer. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'date'
|
25
|
+
require 'rake'
|
26
|
+
|
27
|
+
require 'rake/tasklib'
|
28
|
+
|
29
|
+
require 'raketeer/bump_ver'
|
30
|
+
require 'raketeer/files_bumper'
|
31
|
+
require 'raketeer/sem_ver'
|
32
|
+
require 'raketeer/util'
|
33
|
+
|
34
|
+
module Raketeer
|
35
|
+
###
|
36
|
+
# @author Jonathan Bradley Whited (@esotericpig)
|
37
|
+
# @since 0.2.4
|
38
|
+
###
|
39
|
+
class BumpTask < Rake::TaskLib
|
40
|
+
attr_accessor :bump_bundle
|
41
|
+
attr_accessor :bump_files # Looks for a version number
|
42
|
+
attr_accessor :bundle_cmd
|
43
|
+
attr_accessor :changelogs # Looks for 'Unreleased' & a Markdown header
|
44
|
+
attr_accessor :dry_run
|
45
|
+
attr_accessor :git_msg
|
46
|
+
attr_accessor :name
|
47
|
+
attr_accessor :ruby_files # Looks for {ruby_var}
|
48
|
+
attr_accessor :ruby_var
|
49
|
+
|
50
|
+
alias_method :bump_bundle?,:bump_bundle
|
51
|
+
alias_method :dry_run?,:dry_run
|
52
|
+
|
53
|
+
def initialize(name=:bump)
|
54
|
+
super()
|
55
|
+
|
56
|
+
@bump_bundle = false
|
57
|
+
@bump_files = Rake::FileList[]
|
58
|
+
@bundle_cmd = 'bundle'
|
59
|
+
@changelogs = Rake::FileList['CHANGELOG.md']
|
60
|
+
@dry_run = false
|
61
|
+
@git_msg = %q(git commit -m 'Bump version to v%{version}')
|
62
|
+
@name = name
|
63
|
+
@ruby_files = Rake::FileList[File.join('lib','**','version.rb')]
|
64
|
+
@ruby_var = 'VERSION'
|
65
|
+
|
66
|
+
yield self if block_given?()
|
67
|
+
define()
|
68
|
+
end
|
69
|
+
|
70
|
+
def define()
|
71
|
+
desc 'Show/Set/Bump the version'
|
72
|
+
task @name,[:version] do |task,args|
|
73
|
+
check_env()
|
74
|
+
bump_all(BumpVer.new(
|
75
|
+
version: args.version,
|
76
|
+
major: ENV['major'],
|
77
|
+
minor: ENV['minor'],
|
78
|
+
patch: ENV['patch'],
|
79
|
+
prerelease: ENV['pre'],
|
80
|
+
build_meta: ENV['build']
|
81
|
+
))
|
82
|
+
end
|
83
|
+
|
84
|
+
namespace @name do
|
85
|
+
desc 'Bump/Set the major version'
|
86
|
+
task :major,[:major] do |task,args|
|
87
|
+
bump_ver = BumpVer.new(major: args.major)
|
88
|
+
|
89
|
+
# You can't erase the major version (required)
|
90
|
+
bump_ver.major = '+1' if bump_ver.major.nil?() || bump_ver.major.empty?()
|
91
|
+
|
92
|
+
check_env()
|
93
|
+
bump_all(bump_ver)
|
94
|
+
end
|
95
|
+
|
96
|
+
desc 'Bump/Set the minor version'
|
97
|
+
task :minor,[:minor] do |task,args|
|
98
|
+
bump_ver = BumpVer.new(minor: args.minor)
|
99
|
+
bump_ver.minor = '+1' if bump_ver.minor.nil?()
|
100
|
+
|
101
|
+
check_env()
|
102
|
+
bump_all(bump_ver)
|
103
|
+
end
|
104
|
+
|
105
|
+
desc 'Bump/Set the patch version'
|
106
|
+
task :patch,[:patch] do |task,args|
|
107
|
+
bump_ver = BumpVer.new(patch: args.patch)
|
108
|
+
bump_ver.patch = '+1' if bump_ver.patch.nil?()
|
109
|
+
|
110
|
+
check_env()
|
111
|
+
bump_all(bump_ver)
|
112
|
+
end
|
113
|
+
|
114
|
+
desc 'Set/Erase the pre-release version'
|
115
|
+
task :pre,[:pre] do |task,args|
|
116
|
+
bump_ver = BumpVer.new(prerelease: args.pre)
|
117
|
+
bump_ver.prerelease = '' if bump_ver.prerelease.nil?()
|
118
|
+
|
119
|
+
check_env()
|
120
|
+
bump_all(bump_ver)
|
121
|
+
end
|
122
|
+
|
123
|
+
desc 'Set/Erase the build metadata'
|
124
|
+
task :build,[:build] do |task,args|
|
125
|
+
bump_ver = BumpVer.new(build_meta: args.build)
|
126
|
+
bump_ver.build_meta = '' if bump_ver.build_meta.nil?()
|
127
|
+
|
128
|
+
check_env()
|
129
|
+
bump_all(bump_ver)
|
130
|
+
end
|
131
|
+
|
132
|
+
desc 'Bump the Gemfile.lock version'
|
133
|
+
task :bundle do
|
134
|
+
check_env()
|
135
|
+
bump_bundle_file()
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "Show the help/usage for #{name} tasks"
|
139
|
+
task :help do
|
140
|
+
print_help()
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def bump_all(bump_ver)
|
146
|
+
sem_vers = []
|
147
|
+
|
148
|
+
# Order matters for outputting the most accurate version
|
149
|
+
sem_vers << bump_ruby_files(bump_ver)
|
150
|
+
sem_vers << bump_bump_files(bump_ver)
|
151
|
+
sem_vers << bump_changelogs(bump_ver)
|
152
|
+
|
153
|
+
sem_vers.compact!()
|
154
|
+
|
155
|
+
if @bump_bundle && !bump_ver.empty?() && !sem_vers.empty?()
|
156
|
+
bump_bundle_file()
|
157
|
+
end
|
158
|
+
|
159
|
+
# Always output it, in case the user just wants to see what the git message
|
160
|
+
# should be without making changes.
|
161
|
+
if !@git_msg.nil?() && !sem_vers.empty?()
|
162
|
+
puts '[Git]:'
|
163
|
+
puts '= ' + (@git_msg % {version: sem_vers[0].to_s()})
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def bump_bump_files(bump_ver)
|
168
|
+
bumper = FilesBumper.new(@bump_files,bump_ver,@dry_run)
|
169
|
+
|
170
|
+
bumper.bump_files() do
|
171
|
+
next if bumper.changes > 0 || bumper.line !~ SemVer::REGEX
|
172
|
+
|
173
|
+
break if bumper.bump_line!() && bumper.bump_ver_empty?()
|
174
|
+
end
|
175
|
+
|
176
|
+
return bumper.version
|
177
|
+
end
|
178
|
+
|
179
|
+
def bump_bundle_file()
|
180
|
+
sh_cmd = [@bundle_cmd,'list']
|
181
|
+
|
182
|
+
puts "[#{sh_cmd.join(' ')}]:"
|
183
|
+
|
184
|
+
if @dry_run
|
185
|
+
puts '= Nothing written (dry run)'
|
186
|
+
|
187
|
+
return
|
188
|
+
end
|
189
|
+
|
190
|
+
sh(*sh_cmd,{:verbose => false})
|
191
|
+
end
|
192
|
+
|
193
|
+
# @see https://keepachangelog.com/en/1.0.0/
|
194
|
+
def bump_changelogs(bump_ver)
|
195
|
+
bumper = FilesBumper.new(@changelogs,bump_ver,@dry_run) do
|
196
|
+
@header_bumped = false
|
197
|
+
@unreleased_bumped = false
|
198
|
+
end
|
199
|
+
|
200
|
+
header_regex = /\A(\s*##\s*\[+\D*)(#{SemVer::REGEX.to_s()})(.*)\z/m
|
201
|
+
unreleased_regex = /\A.*Unreleased.*http.*\.{3}/
|
202
|
+
|
203
|
+
bumper.bump_files() do
|
204
|
+
if @header_bumped && @unreleased_bumped
|
205
|
+
if bumper.bump_ver_empty?()
|
206
|
+
break
|
207
|
+
else
|
208
|
+
next
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
if bumper.line =~ unreleased_regex
|
213
|
+
next if @unreleased_bumped
|
214
|
+
|
215
|
+
# Match from the end, in case the URL has a number (like '%20')
|
216
|
+
match = bumper.line.match(/(#{SemVer::REGEX.to_s()})(\.{3}.*)\z/m)
|
217
|
+
|
218
|
+
next if match.nil?() || match.length < 3 || (i = match.begin(0)) < 1
|
219
|
+
|
220
|
+
match = [bumper.line[0..i - 1],match[1],match[-1]]
|
221
|
+
|
222
|
+
next if match.any?() {|m| m.nil?() || m.strip().empty?()}
|
223
|
+
|
224
|
+
orig_line = bumper.line.dup()
|
225
|
+
bumper.line = match[1]
|
226
|
+
|
227
|
+
if bumper.bump_line!(add_change: false)
|
228
|
+
bumper.line = match[0] << bumper.line << match[2]
|
229
|
+
|
230
|
+
bumper.add_change(bumper.line,push: false)
|
231
|
+
|
232
|
+
@unreleased_bumped = true
|
233
|
+
else
|
234
|
+
bumper.line = orig_line
|
235
|
+
end
|
236
|
+
elsif !(match = bumper.line.match(header_regex)).nil?()
|
237
|
+
next if @header_bumped || match.length < 4
|
238
|
+
|
239
|
+
match = [match[1],match[2],match[-1]]
|
240
|
+
|
241
|
+
next if match.any?() {|m| m.nil?() || m.strip().empty?()}
|
242
|
+
|
243
|
+
orig_line = bumper.line.dup()
|
244
|
+
bumper.line = match[1]
|
245
|
+
|
246
|
+
if bumper.bump_line!(add_change: false)
|
247
|
+
bumper.line = match[0] << bumper.line
|
248
|
+
|
249
|
+
# Replace the date with today's date for the new Markdown header, if it exists
|
250
|
+
match[2].sub!(/\d+\s*\-\s*\d+\s*\-\s*\d+(.*)\z/m,"#{Date.today().strftime('%F')}\\1")
|
251
|
+
bumper.line << match[2]
|
252
|
+
|
253
|
+
bumper.add_change(bumper.line,push: true)
|
254
|
+
bumper.line << "\n" # Don't print this newline to the console
|
255
|
+
|
256
|
+
@header_bumped = true
|
257
|
+
end
|
258
|
+
|
259
|
+
# We are adding a new Markdown header, so always set the line back to its original value
|
260
|
+
bumper.line = orig_line
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
return bumper.version
|
265
|
+
end
|
266
|
+
|
267
|
+
def bump_ruby_files(bump_ver)
|
268
|
+
bumper = FilesBumper.new(@ruby_files,bump_ver,@dry_run)
|
269
|
+
version_var_regex = /\A(\s*#{Regexp.quote(@ruby_var)}\s*=\D*)(#{SemVer::REGEX.to_s()})(.*)\z/m
|
270
|
+
|
271
|
+
bumper.bump_files() do
|
272
|
+
next if bumper.changes > 0
|
273
|
+
next if (match = bumper.line.match(version_var_regex)).nil?()
|
274
|
+
next if match.length < 4
|
275
|
+
next if match[1..2].any?() {|m| m.nil?() || m.strip().empty?()}
|
276
|
+
|
277
|
+
orig_line = bumper.line.dup()
|
278
|
+
bumper.line = match[2]
|
279
|
+
|
280
|
+
if bumper.bump_line!(add_change: false)
|
281
|
+
bumper.line = match[1] << bumper.line
|
282
|
+
bumper.line << match[-1] unless match[-1].nil?()
|
283
|
+
|
284
|
+
bumper.add_change(bumper.line,push: false)
|
285
|
+
|
286
|
+
break if bumper.bump_ver_empty?()
|
287
|
+
else
|
288
|
+
bumper.line = orig_line
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
return bumper.version
|
293
|
+
end
|
294
|
+
|
295
|
+
def check_env()
|
296
|
+
env_dryrun = ENV['dryrun']
|
297
|
+
|
298
|
+
if !env_dryrun.nil?() && !(env_dryrun = env_dryrun.to_s().strip()).empty?()
|
299
|
+
@dry_run = Util.to_bool(env_dryrun)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def print_help()
|
304
|
+
puts <<-EOH
|
305
|
+
rake #{@name} # Print the current version
|
306
|
+
|
307
|
+
# You can run a dry run for any task (will not write to files)
|
308
|
+
rake #{@name} dryrun=true
|
309
|
+
|
310
|
+
rake #{@name}[1.2.3-alpha.4-beta.5] # Set the version manually
|
311
|
+
rake #{@name} major=1 minor=2 patch=3 # Set the version numbers
|
312
|
+
rake #{@name} pre=alpha.4 build=beta.5 # Set the version extensions
|
313
|
+
rake #{@name} major=+1 minor=+1 patch=+1 # Bump the version numbers by 1
|
314
|
+
rake #{@name} major=+2 minor=+3 patch=+4 # Bump the version numbers by X
|
315
|
+
|
316
|
+
rake #{@name}:major # Bump the major version by 1
|
317
|
+
rake #{@name}:major[1] # Set the major version
|
318
|
+
rake #{@name}:major[+2] # Bump the major version by 2
|
319
|
+
rake #{@name}:minor # Bump the minor version by 1
|
320
|
+
rake #{@name}:minor[2] # Set the minor version
|
321
|
+
rake #{@name}:minor[+3] # Bump the minor version by 3
|
322
|
+
rake #{@name}:patch # Bump the patch version by 1
|
323
|
+
rake #{@name}:patch[3] # Set the patch version
|
324
|
+
rake #{@name}:patch[+4] # Bump the patch version by 4
|
325
|
+
rake #{@name}:pre # Erase the pre-release version
|
326
|
+
rake #{@name}:pre[alpha.4] # Set the pre-release version
|
327
|
+
rake #{@name}:build # Erase the build metadata
|
328
|
+
rake #{@name}:build[beta.5] # Set the build metadata
|
329
|
+
rake #{@name}:bundle # Bump the Gemfile.lock version
|
330
|
+
EOH
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of Raketeer.
|
7
|
+
# Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# Raketeer is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Raketeer is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU Lesser General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU Lesser General Public License
|
20
|
+
# along with Raketeer. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'raketeer/sem_ver'
|
25
|
+
|
26
|
+
module Raketeer
|
27
|
+
###
|
28
|
+
# Bump Version
|
29
|
+
#
|
30
|
+
# @author Jonathan Bradley Whited (@esotericpig)
|
31
|
+
# @since 0.2.4
|
32
|
+
###
|
33
|
+
class BumpVer < SemVer
|
34
|
+
def initialize(version: nil,major: nil,minor: nil,patch: nil,prerelease: nil,build_meta: nil)
|
35
|
+
self.build_meta = build_meta
|
36
|
+
self.major = major
|
37
|
+
self.minor = minor
|
38
|
+
self.patch = patch
|
39
|
+
self.prerelease = prerelease
|
40
|
+
self.version = version
|
41
|
+
end
|
42
|
+
|
43
|
+
def init_int_or_str(obj)
|
44
|
+
return nil if obj.nil?()
|
45
|
+
return obj if obj.is_a?(Integer)
|
46
|
+
|
47
|
+
obj = obj.to_s().strip()
|
48
|
+
|
49
|
+
return obj if obj.empty?() || obj[0] == '+'
|
50
|
+
return obj.to_i()
|
51
|
+
end
|
52
|
+
|
53
|
+
def init_str(obj)
|
54
|
+
return obj.nil?() ? nil : obj.to_s().strip()
|
55
|
+
end
|
56
|
+
|
57
|
+
def bump!(sem_ver)
|
58
|
+
if !@version.nil?()
|
59
|
+
sem_ver.version = @version
|
60
|
+
else
|
61
|
+
if !@major.nil?()
|
62
|
+
if @major.is_a?(Integer)
|
63
|
+
sem_ver.major = @major
|
64
|
+
elsif @major.empty?()
|
65
|
+
sem_ver.major = 0 # There must always be a major version
|
66
|
+
else
|
67
|
+
sem_ver.major = 0 if sem_ver.major.nil?()
|
68
|
+
sem_ver.major += @major.to_i()
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if !@minor.nil?()
|
73
|
+
if @minor.is_a?(Integer)
|
74
|
+
sem_ver.minor = @minor
|
75
|
+
elsif @minor.empty?()
|
76
|
+
sem_ver.minor = nil
|
77
|
+
else
|
78
|
+
sem_ver.minor = 0 if sem_ver.minor.nil?()
|
79
|
+
sem_ver.minor += @minor.to_i()
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
if !@patch.nil?()
|
84
|
+
if @patch.is_a?(Integer)
|
85
|
+
sem_ver.patch = @patch
|
86
|
+
elsif @patch.empty?()
|
87
|
+
sem_ver.patch = nil
|
88
|
+
else
|
89
|
+
sem_ver.patch = 0 if sem_ver.patch.nil?()
|
90
|
+
sem_ver.patch += @patch.to_i()
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
if !@prerelease.nil?()
|
95
|
+
if @prerelease.empty?()
|
96
|
+
sem_ver.prerelease = nil
|
97
|
+
else
|
98
|
+
sem_ver.prerelease = @prerelease
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if !@build_meta.nil?()
|
103
|
+
if @build_meta.empty?()
|
104
|
+
sem_ver.build_meta = nil
|
105
|
+
else
|
106
|
+
sem_ver.build_meta = @build_meta
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
return sem_ver
|
112
|
+
end
|
113
|
+
|
114
|
+
def bump_line!(line,sem_ver)
|
115
|
+
line.sub!(REGEX,bump!(sem_ver).to_s())
|
116
|
+
|
117
|
+
return line
|
118
|
+
end
|
119
|
+
|
120
|
+
def build_meta=(build_meta)
|
121
|
+
super(init_str(build_meta))
|
122
|
+
end
|
123
|
+
|
124
|
+
def major=(major)
|
125
|
+
super(init_int_or_str(major))
|
126
|
+
end
|
127
|
+
|
128
|
+
def minor=(minor)
|
129
|
+
super(init_int_or_str(minor))
|
130
|
+
end
|
131
|
+
|
132
|
+
def patch=(patch)
|
133
|
+
super(init_int_or_str(patch))
|
134
|
+
end
|
135
|
+
|
136
|
+
def prerelease=(prerelease)
|
137
|
+
super(init_str(prerelease))
|
138
|
+
end
|
139
|
+
|
140
|
+
def version=(version)
|
141
|
+
super(init_str(version))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of Raketeer.
|
7
|
+
# Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# Raketeer is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Raketeer is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU Lesser General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU Lesser General Public License
|
20
|
+
# along with Raketeer. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'raketeer/bump_ver'
|
25
|
+
require 'raketeer/sem_ver'
|
26
|
+
|
27
|
+
module Raketeer
|
28
|
+
###
|
29
|
+
# @author Jonathan Bradley Whited (@esotericpig)
|
30
|
+
# @since 0.2.4
|
31
|
+
###
|
32
|
+
class FilesBumper
|
33
|
+
attr_reader :bump_ver
|
34
|
+
attr_reader :bump_ver_empty
|
35
|
+
attr_accessor :changes
|
36
|
+
attr_reader :dry_run
|
37
|
+
attr_reader :files
|
38
|
+
attr_accessor :init_per_file
|
39
|
+
attr_accessor :line
|
40
|
+
attr_accessor :lines
|
41
|
+
attr_accessor :sem_ver
|
42
|
+
attr_accessor :version
|
43
|
+
attr_accessor :version_bumped # Was the version actually bumped?
|
44
|
+
|
45
|
+
alias_method :bump_ver_empty?,:bump_ver_empty
|
46
|
+
alias_method :dry_run?,:dry_run
|
47
|
+
alias_method :version_bumped?,:version_bumped
|
48
|
+
|
49
|
+
def initialize(files,bump_ver,dry_run,&init_per_file)
|
50
|
+
@bump_ver = bump_ver
|
51
|
+
@bump_ver_empty = bump_ver.empty?()
|
52
|
+
@dry_run = dry_run
|
53
|
+
@files = files.to_a()
|
54
|
+
@init_per_file = init_per_file
|
55
|
+
@sem_ver = nil
|
56
|
+
@version = nil
|
57
|
+
@version_bumped = false
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_change(line,push: true)
|
61
|
+
puts "+ #{line}"
|
62
|
+
|
63
|
+
@changes += 1
|
64
|
+
@lines << line if push
|
65
|
+
end
|
66
|
+
|
67
|
+
def bump_files(&block)
|
68
|
+
@files.each do |filename|
|
69
|
+
puts "[#{filename}]:"
|
70
|
+
|
71
|
+
if !File.exist?(filename)
|
72
|
+
puts '! File does not exist'
|
73
|
+
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
@changes = 0 # For possible future use
|
78
|
+
@lines = []
|
79
|
+
@sem_ver = nil
|
80
|
+
|
81
|
+
@init_per_file.call(self) unless @init_per_file.nil?()
|
82
|
+
|
83
|
+
File.foreach(filename) do |line|
|
84
|
+
@line = line
|
85
|
+
|
86
|
+
block.call(self) if !@line.strip().empty?()
|
87
|
+
|
88
|
+
@lines << @line
|
89
|
+
end
|
90
|
+
|
91
|
+
next if bump_ver_empty?()
|
92
|
+
|
93
|
+
print '= '
|
94
|
+
|
95
|
+
if @changes > 0
|
96
|
+
if dry_run?()
|
97
|
+
puts "Nothing written (dry run): #{@sem_ver}"
|
98
|
+
else
|
99
|
+
File.open(filename,'w') do |file|
|
100
|
+
file.puts @lines
|
101
|
+
end
|
102
|
+
|
103
|
+
puts "#{@changes} change#{@changes == 1 ? '' : 's'} written"
|
104
|
+
end
|
105
|
+
else
|
106
|
+
puts "Nothing written (up-to-date): #{@sem_ver}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def bump_line!(add_change: true)
|
112
|
+
@sem_ver = SemVer.parse_line(@line)
|
113
|
+
|
114
|
+
return false if @sem_ver.nil?()
|
115
|
+
|
116
|
+
@version = @sem_ver if @version.nil?()
|
117
|
+
|
118
|
+
if bump_ver_empty?()
|
119
|
+
puts "= #{@sem_ver}"
|
120
|
+
|
121
|
+
return true
|
122
|
+
else
|
123
|
+
orig_line = @line.dup()
|
124
|
+
@bump_ver.bump_line!(@line,@sem_ver)
|
125
|
+
|
126
|
+
if @line != orig_line
|
127
|
+
if !@version_bumped
|
128
|
+
@version = @sem_ver
|
129
|
+
@version_bumped = true
|
130
|
+
end
|
131
|
+
|
132
|
+
self.add_change(@line,push: false) if add_change
|
133
|
+
|
134
|
+
return true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
return false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of Raketeer.
|
7
|
+
# Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# Raketeer is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Raketeer is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU Lesser General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU Lesser General Public License
|
20
|
+
# along with Raketeer. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
module Raketeer
|
25
|
+
###
|
26
|
+
# Semantic Version
|
27
|
+
#
|
28
|
+
# This is a non-strict version of Semantic Versioning v2.0.0.
|
29
|
+
#
|
30
|
+
# @author Jonathan Bradley Whited (@esotericpig)
|
31
|
+
# @since 0.2.4
|
32
|
+
# @see https://semver.org
|
33
|
+
###
|
34
|
+
class SemVer
|
35
|
+
REGEX = /\d+(\.\d+)?(\.\d+)?(\-[0-9A-Za-z\-\.]+)?(\+[0-9A-Za-z\-\.]+)?/
|
36
|
+
|
37
|
+
attr_accessor :build_meta
|
38
|
+
attr_accessor :major
|
39
|
+
attr_accessor :minor
|
40
|
+
attr_accessor :patch
|
41
|
+
attr_accessor :prerelease
|
42
|
+
attr_accessor :version # If not +nil+, {to_s} will only return this.
|
43
|
+
|
44
|
+
def initialize(major: nil,minor: nil,patch: nil,prerelease: nil,build_meta: nil)
|
45
|
+
@build_meta = build_meta
|
46
|
+
@major = major
|
47
|
+
@minor = minor
|
48
|
+
@patch = patch
|
49
|
+
@prerelease = prerelease
|
50
|
+
@version = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize_copy(orig)
|
54
|
+
super(orig)
|
55
|
+
|
56
|
+
is_clone = caller[0].include?('clone')
|
57
|
+
|
58
|
+
@build_meta = is_clone ? orig.build_meta.clone() : orig.build_meta.dup()
|
59
|
+
@major = is_clone ? orig.major.clone() : orig.major.dup()
|
60
|
+
@minor = is_clone ? orig.minor.clone() : orig.minor.dup()
|
61
|
+
@patch = is_clone ? orig.patch.clone() : orig.patch.dup()
|
62
|
+
@prerelease = is_clone ? orig.prerelease.clone() : orig.prerelease.dup()
|
63
|
+
@version = is_clone ? orig.version.clone() : orig.version.dup()
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.parse(str)
|
67
|
+
# Parsing backwards makes the logic easier
|
68
|
+
build_meta = str.split('+',2)
|
69
|
+
prerelease = build_meta[0].split('-',2)
|
70
|
+
numbers = prerelease[0].split('.',3)
|
71
|
+
|
72
|
+
sem_ver = SemVer.new()
|
73
|
+
sem_ver.major = numbers[0].to_i() # There must always be a major version
|
74
|
+
|
75
|
+
if numbers.length >= 2
|
76
|
+
minor = numbers[1].strip()
|
77
|
+
sem_ver.minor = minor.to_i() unless minor.empty?()
|
78
|
+
|
79
|
+
if numbers.length == 3
|
80
|
+
patch = numbers[2].strip()
|
81
|
+
sem_ver.patch = patch.to_i() unless patch.empty?()
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if prerelease.length == 2
|
86
|
+
prerelease = prerelease[1].strip()
|
87
|
+
sem_ver.prerelease = prerelease unless prerelease.empty?()
|
88
|
+
end
|
89
|
+
|
90
|
+
if build_meta.length == 2
|
91
|
+
build_meta = build_meta[1].strip()
|
92
|
+
sem_ver.build_meta = build_meta unless build_meta.empty?()
|
93
|
+
end
|
94
|
+
|
95
|
+
return sem_ver
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.parse_line(line)
|
99
|
+
str = line[REGEX]
|
100
|
+
|
101
|
+
return nil if str.nil?() || (str = str.strip()).empty?()
|
102
|
+
return parse(str)
|
103
|
+
end
|
104
|
+
|
105
|
+
def empty?()
|
106
|
+
return @build_meta.nil?() &&
|
107
|
+
@major.nil?() &&
|
108
|
+
@minor.nil?() &&
|
109
|
+
@patch.nil?() &&
|
110
|
+
@prerelease.nil?() &&
|
111
|
+
@version.nil?()
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_s()
|
115
|
+
s = ''.dup()
|
116
|
+
|
117
|
+
if !@version.nil?()
|
118
|
+
s << @version.to_s()
|
119
|
+
elsif !@major.nil?()
|
120
|
+
s << @major.to_s()
|
121
|
+
s << ".#{@minor.to_s()}" unless @minor.nil?()
|
122
|
+
s << ".#{@patch.to_s()}" unless @patch.nil?()
|
123
|
+
s << "-#{@prerelease.to_s()}" unless @prerelease.nil?()
|
124
|
+
s << "+#{@build_meta.to_s()}" unless @build_meta.nil?()
|
125
|
+
end
|
126
|
+
|
127
|
+
return s
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/raketeer/util.rb
CHANGED
@@ -27,17 +27,15 @@ module Raketeer
|
|
27
27
|
# @since 0.2.2
|
28
28
|
###
|
29
29
|
module Util
|
30
|
+
# @since 0.2.4
|
31
|
+
TRUE_BOOLS = ['1','on','t','true','y','yes'].freeze()
|
32
|
+
|
30
33
|
def self.find_main_executable(bin_dir)
|
31
|
-
# Try
|
34
|
+
# Try the bin/ dir
|
32
35
|
main_exe = Dir.glob(File.join(bin_dir,'*'))
|
33
36
|
|
34
37
|
return File.basename(main_exe[0]) if main_exe.length == 1
|
35
38
|
|
36
|
-
# Try only .rb files
|
37
|
-
main_exe = Dir.glob(File.join(bin_dir,'*.rb'))
|
38
|
-
|
39
|
-
return File.basename(main_exe[0]) if main_exe.length == 1
|
40
|
-
|
41
39
|
# Try using the main module
|
42
40
|
main_mod = find_main_module()
|
43
41
|
|
@@ -63,5 +61,10 @@ module Raketeer
|
|
63
61
|
|
64
62
|
return nil
|
65
63
|
end
|
64
|
+
|
65
|
+
# @since 0.2.4
|
66
|
+
def self.to_bool(obj)
|
67
|
+
return TRUE_BOOLS.include?(obj.to_s().downcase())
|
68
|
+
end
|
66
69
|
end
|
67
70
|
end
|
data/lib/raketeer/version.rb
CHANGED
@@ -22,5 +22,19 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
module Raketeer
|
25
|
-
VERSION = '0.2.
|
25
|
+
VERSION = '0.2.4'
|
26
|
+
|
27
|
+
# @since 0.2.4
|
28
|
+
DEP_VERSIONS = {
|
29
|
+
'irb' => '~> 1.0'
|
30
|
+
}
|
31
|
+
|
32
|
+
# @since 0.2.4
|
33
|
+
def self.try_require_dev(gem_name)
|
34
|
+
begin
|
35
|
+
require gem_name
|
36
|
+
rescue LoadError => e
|
37
|
+
raise e.exception("Add development dependency: '#{gem_name}','#{DEP_VERSIONS[gem_name]}'")
|
38
|
+
end
|
39
|
+
end
|
26
40
|
end
|
data/raketeer.gemspec
CHANGED
@@ -52,8 +52,9 @@ Gem::Specification.new() do |spec|
|
|
52
52
|
spec.required_ruby_version = '>= 2.1.10'
|
53
53
|
|
54
54
|
# TODO: also add the below comment to the README & reword for user
|
55
|
+
#
|
55
56
|
# If it is a dependency specific to a task, then it should probably be added
|
56
|
-
# as a
|
57
|
+
# as a development dependency (not a runtime dependency) so that a bunch of
|
57
58
|
# non-essential dependencies (to the user) are not added.
|
58
59
|
#
|
59
60
|
# For example, if the user only uses the Nokogiri tasks, then they don't need
|
@@ -63,9 +64,11 @@ Gem::Specification.new() do |spec|
|
|
63
64
|
# If the user uses the IRB task, then they will have to add 'irb' as a
|
64
65
|
# development dependency in their own project's Gemspec.
|
65
66
|
|
67
|
+
dv = Raketeer::DEP_VERSIONS
|
68
|
+
|
66
69
|
spec.add_runtime_dependency 'rake' #,'~> 12.3'
|
67
70
|
|
68
71
|
spec.add_development_dependency 'bundler','~> 1.17'
|
69
|
-
spec.add_development_dependency 'irb' ,'
|
70
|
-
spec.add_development_dependency 'yard' ,'~> 0.9' # For
|
72
|
+
spec.add_development_dependency 'irb' ,dv['irb'] # For IRBTask
|
73
|
+
spec.add_development_dependency 'yard' ,'~> 0.9' # For documentation
|
71
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raketeer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bradley Whited (@esotericpig)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,12 +80,17 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/raketeer.rb
|
82
82
|
- lib/raketeer/all.rb
|
83
|
+
- lib/raketeer/bump.rb
|
84
|
+
- lib/raketeer/bump_task.rb
|
85
|
+
- lib/raketeer/bump_ver.rb
|
86
|
+
- lib/raketeer/files_bumper.rb
|
83
87
|
- lib/raketeer/irb.rb
|
84
88
|
- lib/raketeer/irb_task.rb
|
85
89
|
- lib/raketeer/nokogiri_install_tasks.rb
|
86
90
|
- lib/raketeer/nokogiri_installs.rb
|
87
91
|
- lib/raketeer/run.rb
|
88
92
|
- lib/raketeer/run_task.rb
|
93
|
+
- lib/raketeer/sem_ver.rb
|
89
94
|
- lib/raketeer/util.rb
|
90
95
|
- lib/raketeer/version.rb
|
91
96
|
- raketeer.gemspec
|