-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature:gem] Add gem:release rake task (#36)
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,65 @@ | ||
require 'thor' | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new :spec | ||
|
||
desc 'Run application specs' | ||
task default: [:spec] | ||
|
||
desc 'Debug the gem (load into IRB)' | ||
task :debug do | ||
exec 'bundle exec rake install && irb -I lib/arx.rb -r arx' | ||
namespace :gem do | ||
class T < Thor | ||
include Thor::Actions | ||
end | ||
|
||
desc 'Debug the gem (load into IRB)' | ||
task :debug do | ||
exec 'bundle exec rake install && irb -I lib/arx.rb -r arx' | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ module Arx | |
major: 0, | ||
minor: 3, | ||
patch: 1, | ||
meta: nil | ||
meta: nil, | ||
}.compact.values.join('.').freeze | ||
end |