-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
65 lines (50 loc) · 1.56 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'thor'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new :spec
desc 'Run application specs'
task default: [:spec]
namespace :gem do
class T < Thor
include Thor::Actions
end
desc 'Debug the gem (load into IRB)'
task :debug do
exec 'bin/console'
end
desc 'Prepare a new gem release'
task :release, %i[major minor patch meta] do |task, args|
array = args.to_a
raise ArgumentError.new("Expected at least 3 SemVer segments, got #{array.size}") if array.size < 3
raise ArgumentError.new("Expected no more than 4 SemVer segments, got #{array.size}") if array.size > 4
args.to_h.each_with_index do |(segment, value), index|
next if index == array.size - 1 && array.size == 4
raise TypeError.new("Invalid #{segment} SemVer segment: #{value}") unless value == value.to_i.to_s
end
versions = args.to_h.transform_values {|v| v.to_i if Integer(v) rescue v}
versions[:meta] ||= nil
update_version versions
version = versions.compact.values.join('.')
add_changelog_entry version
end
private
def update_version(versions)
versions.each do |segment, value|
thor :gsub_file, File.join(__dir__, 'lib', 'arx', 'version.rb'), /#{segment}: .*,/, "#{segment}: #{value.inspect},"
end
end
def add_changelog_entry(version)
thor :insert_into_file, File.join(__dir__, 'CHANGELOG.md'), after: /\A/ do
<<-ENTRY
# #{version}
#### Major changes
- TODO
#### Minor changes
- TODO
ENTRY
end
end
def thor(*args, &block)
T.new.send *args, &block
end
end