diff --git a/lib/release/base.rb b/lib/release/base.rb index 5635fac..602a217 100644 --- a/lib/release/base.rb +++ b/lib/release/base.rb @@ -27,20 +27,28 @@ module Release private + def show_existing_tags + git_local_list_tags(release_tag_prefix).join("\n") + end + def validate_version_format (version) - error "Invalid version number format. Try using MAJOR.MINOR.PATCH." unless version =~ /\d+\.\d+\.\d+/ + error "Invalid version number format. Try using MAJOR.MINOR.PATCH." unless version =~ version_pattern end 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: \n#{show_existing_tags}" if git_local_list_tags(release_tag_prefix).include? release_tag_from_version(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}" + error "Version does not exist: \n#{show_existing_tags}" unless git_local_list_tags(release_tag_prefix).include? release_tag_from_version(version) + end + + def validate_version_does_not_exist (version) + error "Version already exists: \n#{show_existing_tags}" if git_local_list_tags(release_tag_prefix).include? release_tag_from_version(version) end def validate_current_branch_is_release - error "Invalid release branch: #{current_branch}" unless current_branch =~ /\d+\.\d+\.\d+/ + error "Invalid release branch: #{current_branch}" unless current_branch =~ release_branch_pattern end def validate_current_branch_master @@ -50,6 +58,8 @@ module Release def validate_release_branch_does_not_exist (branch) error "Version branch already exists: #{branch}" if remote_branch(branch) != "" end + + end end diff --git a/lib/release/commander.rb b/lib/release/commander.rb index 9ed2f9f..8389407 100644 --- a/lib/release/commander.rb +++ b/lib/release/commander.rb @@ -12,7 +12,8 @@ module Release :minor, :patch, :tab, - :trash + :trash, + :versions ].sort DEFAULT = :help diff --git a/lib/release/finish.rb b/lib/release/finish.rb index 4231410..519955f 100644 --- a/lib/release/finish.rb +++ b/lib/release/finish.rb @@ -18,7 +18,7 @@ module Release git_pull release_branch - git_local_tag release_branch + git_local_tag release_tag_from_version(version_from_release_branch(release_branch)) git_push release_branch diff --git a/lib/release/init.rb b/lib/release/init.rb index 673ded7..30cef28 100644 --- a/lib/release/init.rb +++ b/lib/release/init.rb @@ -15,13 +15,13 @@ module Release subcommand, version, *extras = *argv validate_version_format version - + validate_current_branch_master git_pull current_branch validate_version_is_new version - git_local_tag version + git_local_tag release_tag_from_version(version) git_push_tags diff --git a/lib/release/new_version.rb b/lib/release/new_version.rb index fc46995..48bd8ae 100644 --- a/lib/release/new_version.rb +++ b/lib/release/new_version.rb @@ -21,12 +21,13 @@ module Release validate_version_exists version - new_branch = increment_version(version) - validate_release_branch_does_not_exist(new_branch) + new_version = increment_version(version) + validate_version_does_not_exist new_version + validate_release_branch_does_not_exist(release_branch_from_version(new_version)) - git_local_branch_create new_branch, "v#{version}" + git_local_branch_create release_branch_from_version(new_version), release_tag_from_version(version) - git_push new_branch + git_push release_branch_from_version(new_version) end private diff --git a/lib/release/versions.rb b/lib/release/versions.rb new file mode 100644 index 0000000..2a61d59 --- /dev/null +++ b/lib/release/versions.rb @@ -0,0 +1,21 @@ +require_relative './base' + +module Release + + class Versions < Release::Base + def valid? + true + end + + def help + "release versions" + end + + def execute + puts + puts show_existing_tags + puts + end + end + +end diff --git a/lib/shared/branchability.rb b/lib/shared/branchability.rb index 957f568..808bc10 100644 --- a/lib/shared/branchability.rb +++ b/lib/shared/branchability.rb @@ -13,6 +13,30 @@ module Shared ['master'] end + def version_pattern + /\d+\.\d+\.\d+/ + end + + def release_branch_pattern + /rc\d+\.\d+\.\d+/ + end + + def release_branch_from_version (version) + "rc#{version}" + end + + def release_tag_prefix + 'v' + end + + def release_tag_from_version (version) + "v#{version}" + end + + def version_from_release_branch (branch) + branch.sub(/^rc/, '') + end + def parse_branch (branch) parts = branch.split('-') error "invalid branch: user-standard-feature" unless parts.size > 2 @@ -20,7 +44,7 @@ module Shared user = parts.shift standard = parts.shift error "invalid user: #{user}" unless [ENV['FEATURE_USER'],ENV['USER']].include? user - error "invalid branch: #{standard}" unless standard_branches.include? standard or standard =~ /\d+\.\d+\.\d+/ + error "invalid branch: #{standard}" unless standard_branches.include? standard or standard =~ release_branch_pattern feature = parts.join('-') { user: user, standard: standard, feature: feature } end diff --git a/lib/shared/runnable.rb b/lib/shared/runnable.rb index e0749f2..d3dc3b5 100644 --- a/lib/shared/runnable.rb +++ b/lib/shared/runnable.rb @@ -40,11 +40,11 @@ module Shared end def git_local_tag ( tag ) - run_cmd "git tag -a 'v#{tag}' -m 'v#{tag}'" + run_cmd "git tag -a '#{tag}' -m '#{tag}'" end - def git_local_list_tags - `git tag -l 'v*'`.strip.split(/\s+/).sort + def git_local_list_tags (release_tag_prefix) + `git tag -l '#{release_tag_prefix}*'`.strip.split(/\s+/).sort end def git_prune