release: cleanup patch, minor, major

This commit is contained in:
rkiel
2017-09-20 21:40:56 -04:00
parent 6e0e2ab92d
commit 3dc88f3dc4
6 changed files with 80 additions and 84 deletions

View File

@@ -26,17 +26,25 @@ module Release
end end
private private
def validate_version_format (version) def validate_version_format (version)
error "invalid version number format: #{version}" unless version =~ /\d+\.\d+\.\d+/ error "Invalid version number format. Try using MAJOR.MINOR.PATCH." unless version =~ /\d+\.\d+\.\d+/
end end
def validate_version_is_new (version) def validate_version_is_new (version)
error "version already exists: #{git_local_list_tags.join(' ')}" if git_local_list_tags.include? "v#{version}" error "Version already exists: #{git_local_list_tags.join(' ')}" if git_local_list_tags.include? "v#{version}"
end
def validate_version_exists (version)
error "Version does not exist: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}"
end end
def validate_current_branch_master def validate_current_branch_master
error "invalid starting branch: #{current_branch}" unless standard_branches.include? current_branch error "Invalid starting branch: #{current_branch}. Try switching to #{standard_branches.join(' ')}." unless standard_branches.include? current_branch
end
def validate_release_branch_does_not_exist (branch)
error "Version branch already exists: #{branch}" if remote_branch(branch) != ""
end end
end end

View File

@@ -15,11 +15,12 @@ module Release
subcommand, version, *extras = *argv subcommand, version, *extras = *argv
validate_version_format version validate_version_format version
validate_version_is_new version
validate_current_branch_master validate_current_branch_master
git_pull current_branch git_pull current_branch
validate_version_is_new version
git_local_tag version git_local_tag version
git_push_tags git_push_tags

View File

@@ -1,35 +1,16 @@
require_relative './base' require_relative './new_version'
module Release module Release
class Major < Release::Base class Major < Release::NewVersion
def valid?
argv.size > 1
end
def help
"release major version"
end
def execute
subcommand, version, *extras = *argv
error "invalid version: #{version}" unless version =~ /\d+\.\d+\.\d+/
error "unknown version: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}"
error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch
major_branch = major(version)
git_pull current_branch
git_local_branch_create major_branch, "v#{version}"
git_push major_branch
end
private private
def major (version) def subcommand_name
"major"
end
def increment_version (version)
numbers = version.split('.').map { |x| x.to_i } numbers = version.split('.').map { |x| x.to_i }
"#{numbers[0]+1}.0.0" "#{numbers[0]+1}.0.0"
end end

View File

@@ -1,35 +1,16 @@
require_relative './base' require_relative './new_version'
module Release module Release
class Minor < Release::Base class Minor < Release::NewVersion
def valid?
argv.size > 1
end
def help
"release minor version"
end
def execute
subcommand, version, *extras = *argv
error "invalid version: #{version}" unless version =~ /\d+\.\d+\.\d+/
error "unknown version: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}"
error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch
minor_branch = minor(version)
git_pull current_branch
git_local_branch_create minor_branch, "v#{version}"
git_push minor_branch
end
private private
def minor (version) def subcommand_name
"minor"
end
def increment_version (version)
numbers = version.split('.').map { |x| x.to_i } numbers = version.split('.').map { |x| x.to_i }
"#{numbers[0]}.#{numbers[1]+1}.0" "#{numbers[0]}.#{numbers[1]+1}.0"
end end

View File

@@ -0,0 +1,44 @@
require_relative './base'
module Release
class NewVersion < Release::Base
def valid?
argv.size > 1
end
def help
"release #{subcommand_name} version"
end
def execute
subcommand, version, *extras = *argv
validate_version_format version
validate_current_branch_master
git_pull current_branch
validate_version_exists version
new_branch = increment_version(version)
validate_release_branch_does_not_exist(new_branch)
git_local_branch_create new_branch, "v#{version}"
git_push new_branch
end
private
def subcommand_name
error "override"
end
def increment_version (version)
error "override"
end
end
end

View File

@@ -1,35 +1,16 @@
require_relative './base' require_relative './new_version'
module Release module Release
class Patch < Release::Base class Patch < Release::NewVersion
def valid?
argv.size > 1
end
def help
"release patch version"
end
def execute
subcommand, version, *extras = *argv
error "invalid version: #{version}" unless version =~ /\d+\.\d+\.\d+/
error "unknown version: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}"
error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch
patch_branch = patch(version)
git_pull current_branch
git_local_branch_create patch_branch, "v#{version}"
git_push patch_branch
end
private private
def patch (version) def subcommand_name
"patch"
end
def increment_version (version)
numbers = version.split('.').map { |x| x.to_i } numbers = version.split('.').map { |x| x.to_i }
"#{numbers[0]}.#{numbers[1]}.#{numbers[2]+1}" "#{numbers[0]}.#{numbers[1]}.#{numbers[2]+1}"
end end