rake-extensions 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rake-extensions.rb +271 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e948cd0422be068bbdc266db575e33aa919e12a
|
4
|
+
data.tar.gz: 464c3b82f9b9012279a178ac6dafbfacb726143d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59af0126a1185d707f6eabccbdba82feaaeca4a26dfef86d1b0cc9c9a57d49d609c41f5a2d1dc54d2ec4bfe30000ba5c7c1fe0b6135c3a215547432307ddd296
|
7
|
+
data.tar.gz: 769e3d4165487649ce5a34f50133ffee5ef2e78b693a300500b0cf1dfa5ec80af13d8dd20b614354ba78568f8f60ce5e282a0573b41dd1dfd80dd798d80fb8ac
|
@@ -0,0 +1,271 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# os detection
|
6
|
+
module OS
|
7
|
+
def OS.windows?
|
8
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def OS.mac?
|
12
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def OS.unix?
|
16
|
+
!OS.windows?
|
17
|
+
end
|
18
|
+
|
19
|
+
def OS.linux?
|
20
|
+
OS.unix? and not OS.mac?
|
21
|
+
end
|
22
|
+
|
23
|
+
def OS.jruby?
|
24
|
+
RUBY_ENGINE == 'jruby'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# benchmarking tasks
|
29
|
+
$task_benchmarks = []
|
30
|
+
|
31
|
+
class Rake::Task
|
32
|
+
def execute_with_benchmark(*args)
|
33
|
+
bm = Benchmark.realtime { execute_without_benchmark(*args) }
|
34
|
+
$task_benchmarks << [name, bm]
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :execute_without_benchmark, :execute
|
38
|
+
alias_method :execute, :execute_with_benchmark
|
39
|
+
end
|
40
|
+
|
41
|
+
at_exit do
|
42
|
+
total_time = $task_benchmarks.reduce(0) {|acc, x| acc + x[1]}
|
43
|
+
$task_benchmarks
|
44
|
+
.sort { |a, b| b[1] <=> a[1] }
|
45
|
+
.each do |res|
|
46
|
+
percentage = res[1]/total_time * 100
|
47
|
+
if percentage.round > 0
|
48
|
+
percentage_bar = ""
|
49
|
+
percentage.round.times { percentage_bar += "|" }
|
50
|
+
puts "#{percentage_bar} (#{'%.1f' % percentage} %) #{res[0]} ==> #{'%.1f' % res[1]}s"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
puts "total time was: #{'%.1f' % total_time}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# version management
|
57
|
+
class Versioner
|
58
|
+
def self.for(type, version_dir)
|
59
|
+
case type
|
60
|
+
when :gemspec
|
61
|
+
GemspecVersioner.new(version_dir)
|
62
|
+
when :package_json
|
63
|
+
JsonVersioner.new(version_dir)
|
64
|
+
when :cargo_toml
|
65
|
+
TomlVersioner.new(version_dir)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class TomlVersioner
|
71
|
+
def initialize(version_dir)
|
72
|
+
@version_dir = version_dir
|
73
|
+
end
|
74
|
+
def get_next_version(jump)
|
75
|
+
current_version = get_current_version()
|
76
|
+
v = Version.new(current_version)
|
77
|
+
v.send(jump)
|
78
|
+
end
|
79
|
+
def get_current_version()
|
80
|
+
current_version = nil
|
81
|
+
FileUtils.cd @version_dir, :verbose => false do
|
82
|
+
['Cargo.toml'].each do |file|
|
83
|
+
text = File.read(file)
|
84
|
+
if match = text.match(/^version\s=\s\"(.*)\"/i)
|
85
|
+
current_version = match.captures[0]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
current_version
|
90
|
+
end
|
91
|
+
def increment_version(jump)
|
92
|
+
next_version = get_next_version(jump)
|
93
|
+
puts "increment version from #{get_current_version} ==> #{next_version}"
|
94
|
+
update_version(next_version)
|
95
|
+
end
|
96
|
+
def update_version(new_version)
|
97
|
+
FileUtils.cd @version_dir, :verbose => false do
|
98
|
+
['Cargo.toml'].each do |file|
|
99
|
+
text = File.read(file)
|
100
|
+
new_contents = text.gsub(/^version\s=\s\"\d+\.\d+\.\d+\"/, "version = \"#{new_version}\"")
|
101
|
+
File.open(file, "w") { |f| f.puts new_contents }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
class GemspecVersioner
|
107
|
+
VERSION_REGEX = /^(\s*.*?\.version\s*?=\s*['\"])(.*)(['\"])/i
|
108
|
+
DATE_REGEX = /^(\s*.*?\.date\s*?=\s*['\"])(.*)(['\"])/
|
109
|
+
def initialize(version_dir)
|
110
|
+
@version_dir = version_dir
|
111
|
+
end
|
112
|
+
def get_next_version(jump)
|
113
|
+
current_version = get_current_version()
|
114
|
+
v = Version.new(current_version)
|
115
|
+
v.send(jump)
|
116
|
+
end
|
117
|
+
def get_current_version()
|
118
|
+
current_version = nil
|
119
|
+
FileUtils.cd @version_dir, :verbose => false do
|
120
|
+
FileList['*.gemspec'].each do |file|
|
121
|
+
text = File.read(file)
|
122
|
+
if match = text.match(VERSION_REGEX)
|
123
|
+
current_version = match.captures[1]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
current_version
|
128
|
+
end
|
129
|
+
def increment_version(jump)
|
130
|
+
next_version = get_next_version(jump)
|
131
|
+
puts "increment version from #{get_current_version} ==> #{next_version}"
|
132
|
+
update_version(next_version)
|
133
|
+
end
|
134
|
+
def update_version(new_version)
|
135
|
+
FileUtils.cd @version_dir, :verbose => false do
|
136
|
+
FileList['*.gemspec'].each do |file|
|
137
|
+
text = File.read(file)
|
138
|
+
today = Time.now.strftime("%Y-%m-%d")
|
139
|
+
correct_date_contents = text.gsub(DATE_REGEX, "\\1#{today}\\3")
|
140
|
+
new_contents = correct_date_contents.gsub(VERSION_REGEX, "\\1#{new_version}\\3")
|
141
|
+
File.open(file, "w") { |f| f.write new_contents }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
class JsonVersioner
|
147
|
+
def initialize(version_dir)
|
148
|
+
@version_dir = version_dir
|
149
|
+
end
|
150
|
+
def get_next_version(jump)
|
151
|
+
current_version = get_current_version()
|
152
|
+
v = Version.new(current_version)
|
153
|
+
v.send(jump)
|
154
|
+
end
|
155
|
+
def get_current_version()
|
156
|
+
current_version = nil
|
157
|
+
FileUtils.cd @version_dir, :verbose => false do
|
158
|
+
['package.json'].each do |file|
|
159
|
+
text = File.read(file)
|
160
|
+
if match = text.match(/^\s\s\"version\":\s\"(.*)\"/i)
|
161
|
+
current_version = match.captures[0]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
current_version
|
166
|
+
end
|
167
|
+
def increment_version(jump)
|
168
|
+
next_version = get_next_version(jump)
|
169
|
+
puts "increment version from #{get_current_version} ==> #{next_version}"
|
170
|
+
update_version(next_version)
|
171
|
+
end
|
172
|
+
def update_version(new_version)
|
173
|
+
FileUtils.cd @version_dir, :verbose => false do
|
174
|
+
['package.json'].each do |file|
|
175
|
+
text = File.read(file)
|
176
|
+
new_contents = text.gsub(/^\s\s\"version\":\s\"\d+\.\d+\.\d+\"/, " \"version\": \"#{new_version}\"")
|
177
|
+
File.open(file, "w") { |f| f.puts new_contents }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
class Version < Array
|
184
|
+
def initialize s
|
185
|
+
super(s.split('.').map { |e| e.to_i })
|
186
|
+
end
|
187
|
+
def as_version_code
|
188
|
+
get_major*1000*1000 + get_minor*1000 + get_patch
|
189
|
+
end
|
190
|
+
def < x
|
191
|
+
(self <=> x) < 0
|
192
|
+
end
|
193
|
+
def > x
|
194
|
+
(self <=> x) > 0
|
195
|
+
end
|
196
|
+
def == x
|
197
|
+
(self <=> x) == 0
|
198
|
+
end
|
199
|
+
def patch
|
200
|
+
patch = self.last
|
201
|
+
self[0...-1].concat([patch + 1])
|
202
|
+
end
|
203
|
+
def minor
|
204
|
+
self[1] = self[1] + 1
|
205
|
+
self[2] = 0
|
206
|
+
self
|
207
|
+
end
|
208
|
+
def major
|
209
|
+
self[0] = self[0] + 1
|
210
|
+
self[1] = 0
|
211
|
+
self[2] = 0
|
212
|
+
self
|
213
|
+
end
|
214
|
+
def get_major
|
215
|
+
self[0]
|
216
|
+
end
|
217
|
+
def get_minor
|
218
|
+
self[1]
|
219
|
+
end
|
220
|
+
def get_patch
|
221
|
+
self[2]
|
222
|
+
end
|
223
|
+
def to_s
|
224
|
+
self.join(".")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
## git related utilities
|
229
|
+
desc "push tag to github"
|
230
|
+
task :push do
|
231
|
+
sh "git push origin"
|
232
|
+
current_version = get_current_version
|
233
|
+
sh "git push origin #{current_version}"
|
234
|
+
end
|
235
|
+
def assert_tag_exists(version)
|
236
|
+
raise "tag #{version} missing" if `git tag -l #{version}`.length == 0
|
237
|
+
end
|
238
|
+
def create_changelog(current_version, next_version)
|
239
|
+
sha1s = `git log #{current_version}..HEAD --oneline`.strip.split(/\n/).collect { |line| line.split(' ').first }
|
240
|
+
log_entries = []
|
241
|
+
sha1s.each do |sha1|
|
242
|
+
raw_log = `git log --format=%B -n 1 #{sha1}`.strip
|
243
|
+
log_lines = raw_log.split(/\n/)
|
244
|
+
first_line = true
|
245
|
+
entry = log_lines
|
246
|
+
.reject{|x| x.strip == ""}
|
247
|
+
.collect do |line|
|
248
|
+
if line =~ /^\s*\*/
|
249
|
+
"#{line.sub(/\s*\*/, " *")}"
|
250
|
+
else
|
251
|
+
res = first_line ? "* #{line}" : " #{line}"
|
252
|
+
first_line = false
|
253
|
+
res
|
254
|
+
end
|
255
|
+
end
|
256
|
+
log_entries << entry
|
257
|
+
end
|
258
|
+
log = log_entries.join("\n")
|
259
|
+
|
260
|
+
date = Time.now.strftime("%m/%d/%Y")
|
261
|
+
log_entry = "### [#{next_version}] - #{date}\n#{log}"
|
262
|
+
puts "logmessages:\n#{log}"
|
263
|
+
['CHANGELOG.md'].each do |file|
|
264
|
+
if !File.exist?(file)
|
265
|
+
File.open(file, 'w') {|f| f.write("# Changelog") }
|
266
|
+
end
|
267
|
+
text = File.read(file)
|
268
|
+
new_contents = text.gsub(/^#\sChangelog/, "# Changelog\n\n#{log_entry}")
|
269
|
+
File.open(file, "w") { |f| f.puts new_contents }
|
270
|
+
end
|
271
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Mueller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: useful add-ons for writing rake tasks
|
14
|
+
email: muellero@coldground.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rake-extensions.rb
|
20
|
+
homepage: https://rubygems.org/gems/rake-extensions
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.2.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: collection of rake utilities
|
44
|
+
test_files: []
|