From e64fce137dbff33e3a6b9642f78e9792c7f2ec3a Mon Sep 17 00:00:00 2001 From: Mads Nielsen Date: Mon, 3 Dec 2018 15:13:14 +0100 Subject: [PATCH 1/5] Experiment... --- bin/plusbump | 41 ++++++--- lib/plusbump.rb | 190 ++++++++++++++++++++++++++---------------- spec/plusbump_spec.rb | 95 +++++++++++++++------ 3 files changed, 214 insertions(+), 112 deletions(-) diff --git a/bin/plusbump b/bin/plusbump index f338b62..87a5565 100755 --- a/bin/plusbump +++ b/bin/plusbump @@ -6,23 +6,39 @@ require 'plusbump' doc = < [options] - plusbump --latest= [options] + plusbump ref [options] + plusbump tag [] [options] plusbump --version +Commands: + ref: + Bumps using a git ref as a base. + tag: + Bumps using tags, uses glob patterns to list tags matching, and selects the latest + Arguments: - A git reference. If specified, PlusBump will search for bumps from HEAD back to this instead of searching for a tag. + A git reference. If specified, PlusBump will search for bumps from HEAD back to this instead of searching for a tag. + The base semver version to use as a base when outputting the bumped version. + Git glob pattern tags must match for eligability. The resulting version number tries to filter out the tag glob from the result. + + Examples: + Numeric tag: '[0-9]', captures: 1.0.0, 2.0.0 + Version tag: 'v', captures: v1.0.0, v2.0.0 Options: -h --help Show this screen. - -l --latest= + -t --create-tag + + Tags the current commit with the result of the bump operation + + -p --prefix= - Specify a glob pattern to search for last matching tag instead of - providing a specific ref. - Will attempt to use everything after as the version string - so be sure to provide _entire_ prefix. - E.g. use "R_" if your versions are "R_1.2.3" + Specify the prefix for the new tag name. By default we do not include prefixes in the result. + + -s --start-ref= + + Indicates where the search should start. By default we use 'HEAD' as a starting point. --version Shows current version of PlusBump --debug Debug flag @@ -43,7 +59,8 @@ rescue Docopt::Exit => e exit end -#TODO: input['--latest'].flatten[0] -puts PlusBump.bump(input[''], input['--latest'], debug: input['--debug']) - +result = PlusBump.run(input) +if input['--create-tag'] + PlusBump::Tag.create(result) +end diff --git a/lib/plusbump.rb b/lib/plusbump.rb index b5a8ee9..5d7a399 100644 --- a/lib/plusbump.rb +++ b/lib/plusbump.rb @@ -3,99 +3,143 @@ require 'rugged' module PlusBump - def self.bump(ref, latest, debug: false) - - # Defaults - major = /\+major/ - minor = /\+minor/ - patch = /\+patch/ - base = '0.0.0' - prefix = '' - # Init Repo from current directory - repository = Rugged::Repository.new(Dir.pwd) - tagcollection = Rugged::TagCollection.new(repository) + # Module defaults + BASE = '0.0.0' + MAJOR = '+major' + MINOR = '+minor' + PATCH = '+patch' + + @@repo = nil + + def self.get_repo + unless @@repo + @@repo = Rugged::Repository.new(Dir.pwd) + end + @@repo + end + + class Tag + def self.create(tag_name) + #TODO PlusBump.get_repo.create(tag_name, PlusBump.get_repo.head.target) + puts "Created tag #{tag_name}" + end + end + def self.extract_number(partial) + if /\d+/.match(partial) + /\d+/.match(partial)[0] + end + end + + def self.extract_prefix(partial) + if /\D+/.match(partial) + /\D+/.match(partial)[0] + end + end + + def self.run(input) + if input['tag'] + bump_by_tag(latest: input[''], prefix: input['--prefix'], debug: input['--debug']) + elsif input['ref'] + bump_by_ref(ref: input[''], semver: input[''], prefix: input['--prefix'], debug: input['--debug']) + end + end + def self.create_walker(repository) w = Rugged::Walker.new(repository) # Initialise the walker to start at current HEAD head = repository.lookup(repository.head.target.oid) w.push(head) + return w + end - if latest.nil? - tail = repository.rev_parse(ref) - w.hide(tail) - else - candidates = [] - puts "Searching for at tag that matches the glob pattern: " + latest if debug - tagcollection.each(latest+'*') do |tag| - unless repository.merge_base(tag.target, head).nil? - puts "Found matching tag on correct branch: " + tag.name if debug - candidates << tag - end - end + def self.bump_by_ref(args = {}) + semver_string = args[:semver] ? args[:semver] : PlusBump::BASE + + w = create_walker(PlusBump.get_repo) + tail = PlusBump.get_repo.rev_parse(args[:ref]) + w.hide(tail) + prefix = args[:prefix] ? args[:prefix] : '' - if candidates.empty? - puts "No matching tag found for "+latest - else - candidates.sort! {|a,b| a.target.time <=> b.target.time } - latest_match = candidates.last - puts "Newest matching tag: #{latest_match.name}" if debug - puts "Newest matching tag sha: #{latest_match.target.oid}" if debug - #set target of matching commit as the tail of our walker - w.hide(latest_match.target) - #unless input[''] - base = latest_match.name.sub(latest,'') - puts "latest: #{latest}" if debug - puts "match.Name: #{latest_match.name}" if debug - puts "Base: #{base}" if debug - #end - - end - end + v_number = semver_string.split('.') + v_special = semver_string.split('-') - # Handle X.Y.Z-SPECIAL by saving SPECIAL part for later - split = base.split('-') - v_number = split[0].split('.') - special = '' + if(prefix.empty?) + prefix = extract_prefix(v_number[0]) || '' + end - #TODO: Above could probably be re-written to use the semver gem for parsing. + # Current semver string + result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, '') #TODO: Fix special - major_bump = false - minor_bump = false - patch_bump = false + # Logic bump + bumping = bump_action(w, result) + final_res = prefix + (result.format "%M.%m.%p%s") + return final_res + end - #walk through all commits looking for version bump requests - w.each do |commit| - puts "Commit: " + commit.oid if debug - if major =~ commit.message - puts "bumps major" if debug - major_bump = true - elsif minor =~ commit.message - puts "bump minor" if debug - minor_bump = true - else - patch_bump = true + def self.bump_by_tag(args = {}) + base = '0.0.0' + # Init Repo from current directory + tagcollection = Rugged::TagCollection.new(PlusBump.get_repo) + w = create_walker(PlusBump.get_repo) + head = PlusBump.get_repo.lookup(PlusBump.get_repo.head.target.oid) + candidates = [] + tagcollection.each(args[:latest]+'*') do |tag| + unless PlusBump.get_repo.merge_base(tag.target, head).nil? + candidates << tag end end - result = SemVer.new(v_number[0].to_i, v_number[1].to_i, v_number[2].to_i, special) - - if major_bump - result.major += 1 - result.minor = 0 - result.patch = 0 - elsif minor_bump - result.minor += 1 - result.patch = 0 - elsif patch_bump - result.patch += 1 + if candidates.empty? + puts "No matching tag found for "+args[:latest] else - puts "No version increment" + candidates.sort! {|a,b| a.target.time <=> b.target.time } + latest_match = candidates.last + #set target of matching commit as the tail of our walker + w.hide(latest_match.target) + base = latest_match.name.sub(args[:latest],'') + puts args[:debug] + puts "Found matching tag #{latest_match.name}" if args[:debug] end + + v_number = base.split('.') + v_special = base.split('-') + prefix = args[:prefix] ? args[:prefix] : '' + # Current semver string + result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, '') # TODO: FIX SPECIAL + # Logic bumps + bumping = bump_action(w, result) final_res = prefix + (result.format "%M.%m.%p%s") - return final_res end + + def self.bump_action(walker, semver) + # Defaults + major = /\+major/ + minor = /\+minor/ + patch = /\+patch/ + minor_bump = false + + walker.each do |commit| + if major =~ commit.message + semver.major += 1 + semver.minor = 0 + semver.patch = 0 + return :major + end + if minor =~ commit.message + minor_bump = true + end + end + if(minor_bump) + semver.minor += 1 + semver.patch = 0 + return :minor + else + semver.patch += 1 + return :patch + end + end end diff --git a/spec/plusbump_spec.rb b/spec/plusbump_spec.rb index 894da0b..eb46f61 100644 --- a/spec/plusbump_spec.rb +++ b/spec/plusbump_spec.rb @@ -1,30 +1,71 @@ require 'plusbump' RSpec.describe PlusBump, "#bump" do - specify { - expect { PlusBump.bump(nil, "not_found") }.to output(/No matching tag found for not_found/).to_stdout - } - specify { - expect(`ruby bin/plusbump -blaha`).to match(/Usage:/) - } - context "self smoke test" do - it "should correctly increment minor to 0.1.0" do - expect(PlusBump.bump("5a3cba405f73778b487d56fad3fd4083cfb112b5", nil)).to eq("0.1.0") - end - it "should increment major from first commit" do - expect(PlusBump.bump("e318c48368febb79309e7c371d99bb49fdd5f900", nil)).to eq("1.0.0") - end - it "should increment to major when used against 0.1.* and not be 0.1.0" do - expect(PlusBump.bump(nil, "0.1.")).not_to eq("0.1.0") - end - it "should increment to major when used against 0.1.*" do - expect(PlusBump.bump(nil, "0.1.")).to eq("1.0.0") - end - it "should increment to 1.0.0 when no tag found" do - expect(PlusBump.bump(nil, "not_found")).to eq("1.0.0") - end - it "should incremment to 3.0.0 when semver is prefix" do - expect(PlusBump.bump(nil, "2")).to eq("3.0.0") - end - end -end \ No newline at end of file + + context 'ref command used' do + it "should correctly increment minor to 0.1.0" do + expect(PlusBump.bump_by_ref(ref: "5a3cba405f73778b487d56fad3fd4083cfb112b5")).to eq("0.1.0") + end + it "should increment major from first commit" do + expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900")).to eq("1.0.0") + end + end + + + context '--semver specifed in ref' do + it "should correctly increment minor so version becomes 1.1.0" do + expect(PlusBump.bump_by_ref(ref: "5a3cba405f73778b487d56fad3fd4083cfb112b5", semver: '1.0.0')).to eq("1.1.0") + end + it "should correctly increment major so version becomes 2.0.0" do + expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: '1.0.0')).to eq("2.0.0") + end + it "should correctly increment major so new semver v2.0.0" do + expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: 'v1.0.0')).to eq("v2.0.0") + end + + end + + context '--semver and --prefix specified in ref' do + it "should correctly increment major so new semver v2.0.0 with manually added prefix" do + expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: '1.0.0', prefix: 'v')).to eq("v2.0.0") + end + end + + context 'tag command used' do + + it "should increment to major when used against 0.1.* and not be 0.1.0" do + expect(PlusBump.bump_by_tag(latest: "0.1.")).not_to eq("0.1.0") + end + it "should increment to major when used against 0.1.*" do + expect(PlusBump.bump_by_tag(latest: "0.1.")).to eq("1.0.0") + end + it "should increment to 1.0.0 when no tag found" do + expect(PlusBump.bump_by_tag(latest: "not_found")).to eq("1.0.0") + end + it "should incremment to 3.0.0 when semver is prefix" do + expect(PlusBump.bump_by_tag(latest: "[0-9]")).to eq("3.0.0") + end + end + + context 'tag command used with --prefix switch' do + it "should incremment to 3.0.0 when semver is prefix, and append prefix if specifed" do + expect(PlusBump.bump_by_tag(latest: "[0-9]", prefix: 'v')).to eq("v3.0.0") + end + + it "should increment to correctly with tag prefix" do + expect(PlusBump.bump_by_tag(latest: "R_", prefix: 'R_')).to eq("R_2.1.0") + end + end + + context 'tag should be created' do + specify { expect { PlusBump::Tag.create("1.0.0") }.to output(/Created tag 1.0.0/).to_stdout } + end + + context 'console response behaviour' do + specify { expect { puts PlusBump.bump_by_tag(latest: "R_", prefix: 'R_') }.to output(/R_2.1.0/).to_stdout } + specify { expect { puts PlusBump.bump_by_tag(latest: "R_") }.to output(/2.1.0/).to_stdout } + specify { expect { PlusBump.bump_by_tag(latest: "not_found") }.to output(/No matching tag found for not_found/).to_stdout } + specify { expect(`ruby bin/plusbump -blaha`).to match(/Usage:/) } + end + +end \ No newline at end of file From e173320321b3e954f671b08fe15ecfa0fb03cdf4 Mon Sep 17 00:00:00 2001 From: Mads Nielsen Date: Wed, 20 Feb 2019 10:40:33 +0100 Subject: [PATCH 2/5] Small fixes --- .rubocop.yml | 11 ++++ Gemfile.lock | 41 +++++++++++++++ Rakefile | 16 +++--- bin/console | 6 +-- bin/plusbump | 24 ++++----- lib/plusbump.rb | 98 +++++++++++++++++------------------- lib/plusbump/version.rb | 2 +- pkg/plusbump-2.0.0.beta.gem | Bin 0 -> 9216 bytes plusbump.gemspec | 37 +++++++------- spec/plusbump_spec.rb | 85 +++++++++++++++---------------- spec/spec_helper.rb | 54 -------------------- 11 files changed, 182 insertions(+), 192 deletions(-) create mode 100644 .rubocop.yml create mode 100644 Gemfile.lock create mode 100644 pkg/plusbump-2.0.0.beta.gem diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4ce1f56 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,11 @@ +Metrics/LineLength: + Max: 160 + +Style/FormatStringToken: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Style/MutableConstant: + Enabled: false \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..76a1936 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,41 @@ +PATH + remote: . + specs: + plusbump (2.0.0.beta) + docopt (~> 0.6.1) + rugged (~> 0.26) + semver (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.3) + docopt (0.6.1) + rake (10.5.0) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) + rugged (0.27.4) + semver (1.0.1) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.14) + plusbump! + rake (~> 10.0) + rspec (~> 3.7) + +BUNDLED WITH + 1.16.2 diff --git a/Rakefile b/Rakefile index 9969434..66ad4fa 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,15 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec -desc "Verbose test output" -task :doc do +desc 'Verbose test output' +task :doc do puts `rspec --format doc` -end \ No newline at end of file +end + +task :lint do + puts `rubocop` +end diff --git a/bin/console b/bin/console index df67edc..43518f9 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "plusbump" +require 'bundler/setup' +require 'plusbump' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +10,5 @@ require "plusbump" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/bin/plusbump b/bin/plusbump index 87a5565..8166a72 100755 --- a/bin/plusbump +++ b/bin/plusbump @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -#encoding: utf-8 require 'docopt' require 'plusbump' @@ -12,18 +11,18 @@ Usage: Commands: ref: - Bumps using a git ref as a base. + Bumps using a git ref as a base. tag: - Bumps using tags, uses glob patterns to list tags matching, and selects the latest + Bumps using tags, uses glob patterns to list tags matching, and selects the latest Arguments: - A git reference. If specified, PlusBump will search for bumps from HEAD back to this instead of searching for a tag. + A git reference. If specified, PlusBump will search for bumps from HEAD back to this instead of searching for a tag. The base semver version to use as a base when outputting the bumped version. - Git glob pattern tags must match for eligability. The resulting version number tries to filter out the tag glob from the result. + Git glob pattern tags must match for eligability. The resulting version number tries to filter out the tag glob from the result. Examples: Numeric tag: '[0-9]', captures: 1.0.0, 2.0.0 - Version tag: 'v', captures: v1.0.0, v2.0.0 + Version tag: 'v', captures: v1.0.0, v2.0.0 Options: -h --help Show this screen. @@ -39,9 +38,9 @@ Options: -s --start-ref= Indicates where the search should start. By default we use 'HEAD' as a starting point. - + --version Shows current version of PlusBump - --debug Debug flag + --debug Debug flag DOCOPT @@ -52,15 +51,12 @@ DOCOPT begin # Parse Commandline Arguments - input = Docopt::docopt(doc, version: PlusBump::VERSION) - puts input if input['--debug'] + input = Docopt.docopt(doc, version: PlusBump::VERSION) + puts input if input['--debug'] rescue Docopt::Exit => e puts e.message exit end result = PlusBump.run(input) -if input['--create-tag'] - PlusBump::Tag.create(result) -end - +PlusBump::Tag.create(result) if input['--create-tag'] && result diff --git a/lib/plusbump.rb b/lib/plusbump.rb index 5d7a399..99cf80f 100644 --- a/lib/plusbump.rb +++ b/lib/plusbump.rb @@ -1,49 +1,49 @@ -require "plusbump/version" +require 'plusbump/version' require 'semver' require 'rugged' +# PlusBump main module module PlusBump - # Module defaults BASE = '0.0.0' MAJOR = '+major' MINOR = '+minor' PATCH = '+patch' + @repo = nil - @@repo = nil - - def self.get_repo - unless @@repo - @@repo = Rugged::Repository.new(Dir.pwd) - end - @@repo + def self.repo + @repo ||= Rugged::Repository.new(Dir.pwd) + @repo end + # Class Tag class Tag def self.create(tag_name) - #TODO PlusBump.get_repo.create(tag_name, PlusBump.get_repo.head.target) - puts "Created tag #{tag_name}" - end + target = PlusBump.repo.head.target + ref = PlusBump.repo.tags.create(tag_name, target) + puts "Created tag #{tag_name}" if ref + end + + def self.delete(tag_name) + tag_to_delete = PlusBump.repo.tags[tag_name] + PlusBump.repo.references.delete(tag_to_delete) if tag_to_delete + end end def self.extract_number(partial) - if /\d+/.match(partial) - /\d+/.match(partial)[0] - end + /\d+/.match(partial)[0] if /\d+/ =~ partial end def self.extract_prefix(partial) - if /\D+/.match(partial) - /\D+/.match(partial)[0] - end + /\D+/.match(partial)[0] if /\D+/ =~ partial end - def self.run(input) + def self.run(input) if input['tag'] bump_by_tag(latest: input[''], prefix: input['--prefix'], debug: input['--debug']) elsif input['ref'] bump_by_ref(ref: input[''], semver: input[''], prefix: input['--prefix'], debug: input['--debug']) - end + end end def self.create_walker(repository) @@ -51,68 +51,62 @@ def self.create_walker(repository) # Initialise the walker to start at current HEAD head = repository.lookup(repository.head.target.oid) w.push(head) - return w + w end def self.bump_by_ref(args = {}) - semver_string = args[:semver] ? args[:semver] : PlusBump::BASE - - w = create_walker(PlusBump.get_repo) - tail = PlusBump.get_repo.rev_parse(args[:ref]) + semver_string = args[:semver] || PlusBump::BASE + w = create_walker(PlusBump.repo) + tail = PlusBump.repo.rev_parse(args[:ref]) w.hide(tail) - prefix = args[:prefix] ? args[:prefix] : '' + prefix = args[:prefix] || '' v_number = semver_string.split('.') - v_special = semver_string.split('-') + v_special = semver_string.split('-').size > 1 ? semver_string.split('-')[-1] : '' - if(prefix.empty?) + if prefix.empty? prefix = extract_prefix(v_number[0]) || '' end # Current semver string - result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, '') #TODO: Fix special + result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, v_special) # TODO: Fix special # Logic bump - bumping = bump_action(w, result) + bump_action(w, result) final_res = prefix + (result.format "%M.%m.%p%s") - return final_res end def self.bump_by_tag(args = {}) base = '0.0.0' # Init Repo from current directory - tagcollection = Rugged::TagCollection.new(PlusBump.get_repo) - w = create_walker(PlusBump.get_repo) - head = PlusBump.get_repo.lookup(PlusBump.get_repo.head.target.oid) + tagcollection = Rugged::TagCollection.new(PlusBump.repo) + w = create_walker(PlusBump.repo) + head = PlusBump.repo.lookup(PlusBump.repo.head.target.oid) candidates = [] - tagcollection.each(args[:latest]+'*') do |tag| - unless PlusBump.get_repo.merge_base(tag.target, head).nil? - candidates << tag - end + tagcollection.each(args[:latest] + '*') do |tag| + candidates << tag if !PlusBump.repo.merge_base(tag.target, head).nil? end if candidates.empty? - puts "No matching tag found for "+args[:latest] + puts 'No matching tag found for ' + args[:latest] else - candidates.sort! {|a,b| a.target.time <=> b.target.time } + candidates.sort! { |a,b| a.target.time <=> b.target.time } latest_match = candidates.last - #set target of matching commit as the tail of our walker + # Set target of matching commit as the tail of our walker w.hide(latest_match.target) base = latest_match.name.sub(args[:latest],'') - puts args[:debug] puts "Found matching tag #{latest_match.name}" if args[:debug] end v_number = base.split('.') - v_special = base.split('-') - prefix = args[:prefix] ? args[:prefix] : '' + # v_special = base.split('-') + prefix = args[:prefix] || '' # Current semver string result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, '') # TODO: FIX SPECIAL # Logic bumps - bumping = bump_action(w, result) - final_res = prefix + (result.format "%M.%m.%p%s") - return final_res + bump_action(w, result) + prefix + (result.format "%M.%m.%p%s") end def self.bump_action(walker, semver) @@ -129,17 +123,15 @@ def self.bump_action(walker, semver) semver.patch = 0 return :major end - if minor =~ commit.message - minor_bump = true - end + minor_bump = true if minor =~ commit.message end - if(minor_bump) - semver.minor += 1 + if minor_bump + semver.minor += 1 semver.patch = 0 return :minor else semver.patch += 1 return :patch - end + end end end diff --git a/lib/plusbump/version.rb b/lib/plusbump/version.rb index a9697ba..bfbd69c 100644 --- a/lib/plusbump/version.rb +++ b/lib/plusbump/version.rb @@ -1,3 +1,3 @@ module PlusBump - VERSION = "2.0.0.beta" + VERSION = '2.0.0.beta'.freeze end diff --git a/pkg/plusbump-2.0.0.beta.gem b/pkg/plusbump-2.0.0.beta.gem new file mode 100644 index 0000000000000000000000000000000000000000..083344c0d7400f1e0b0631e9e9026c8b5bf69b52 GIT binary patch literal 9216 zcm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Jzk5UD#iS|6p2W&b*G~Dg6lIx7%-3&Ws3s93J%zkhnC7*;sKBM5j4* zr;a2D)SO#2p(19L+C5G<+eOcz(rorSz95hN>C{N6z4*9^VFncb##dh!d({#$KY4%G z{}O=>03Z-30B6?^hXCEbLzDYE=dgCLwRZOMarNR2uyl3#uv`WpMc{Qm)kUhw}# z{}mDj3jL%1{vG?^-}hQ9u(?-0A9dvdtNYYWj5ZP6IJKx88)g|Uo*hOLPI>Q)8K%m_F9Z|ANn2? zv(4@!p;h*=K~}8c3um?&pc^niy<+5VNTwimn^dUcKa?MyiIrQhKaW~VIzIZmnf-or zz0SFFPy}gV+jvTC1F@R7uZUGJZzN^v+{zK-ZiGdv6|_6sbhfmBauc2X`R&^V-lwDb z)eP1#V^Mx)A3R&C{zVzDPCN@gvXd_zU>kFT1(EE-W%Cl?%Z^#3zhf!>nd2V>{z2d$ J1pZb8{udm#)I$IO literal 0 HcmV?d00001 diff --git a/plusbump.gemspec b/plusbump.gemspec index 3f11b7c..f6b5c01 100644 --- a/plusbump.gemspec +++ b/plusbump.gemspec @@ -1,31 +1,30 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'plusbump/version' Gem::Specification.new do |spec| - spec.name = "plusbump" - spec.version = PlusBump::VERSION - spec.authors = ["Jan Krag", "Mads Nielsen"] - spec.email = ["jak@praqma.net", "man@praqma.net"] + spec.name = 'plusbump' + spec.version = PlusBump::VERSION + spec.authors = ['Jan Krag', 'Mads Nielsen'] + spec.email = ['jak@praqma.net', 'man@praqma.net'] - spec.summary = %q{PlusBump ruby gem} - spec.description = %q{Use this gem to automate the automation of version bumping in git} - spec.homepage = "https://github.com/Praqma/PlusBump" - spec.license = "MIT" + spec.summary = 'PlusBump ruby gem' + spec.description = 'Use this gem to automate the automation of version bumping in git' + spec.homepage = 'https://github.com/Praqma/PlusBump' + spec.license = 'MIT' - spec.files = `git ls-files -z`.split("\x0").reject do |f| + spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features|jenkins-pipeline)/}) end - spec.bindir = "bin" + spec.bindir = 'bin' spec.executables << 'plusbump' - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_development_dependency "bundler", "~> 1.14" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "rspec", "~> 3.7" - spec.add_runtime_dependency 'docopt', "~> 0.6.1" - spec.add_runtime_dependency 'rugged', "~> 0.26" - spec.add_runtime_dependency 'semver', "~> 1.0" + spec.add_development_dependency 'bundler', '~> 1.14' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'rspec', '~> 3.7' + spec.add_runtime_dependency 'docopt', '~> 0.6.1' + spec.add_runtime_dependency 'rugged', '~> 0.26' + spec.add_runtime_dependency 'semver', '~> 1.0' end diff --git a/spec/plusbump_spec.rb b/spec/plusbump_spec.rb index eb46f61..e13ad6c 100644 --- a/spec/plusbump_spec.rb +++ b/spec/plusbump_spec.rb @@ -1,71 +1,72 @@ require 'plusbump' -RSpec.describe PlusBump, "#bump" do +RSpec.configure do |config| + config.before(:all) do + PlusBump::Tag.delete('Test_1.0.0') + end +end +RSpec.describe PlusBump, "#bump" do context 'ref command used' do - it "should correctly increment minor to 0.1.0" do - expect(PlusBump.bump_by_ref(ref: "5a3cba405f73778b487d56fad3fd4083cfb112b5")).to eq("0.1.0") + it 'should correctly increment minor to 0.1.0' do + expect(PlusBump.bump_by_ref(ref: '5a3cba405f73778b487d56fad3fd4083cfb112b5')).to eq('0.1.0') + end + it 'should increment major from first commit' do + expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900')).to eq('1.0.0') end - it "should increment major from first commit" do - expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900")).to eq("1.0.0") - end end - context '--semver specifed in ref' do - it "should correctly increment minor so version becomes 1.1.0" do - expect(PlusBump.bump_by_ref(ref: "5a3cba405f73778b487d56fad3fd4083cfb112b5", semver: '1.0.0')).to eq("1.1.0") + it 'should correctly increment minor so version becomes 1.1.0' do + expect(PlusBump.bump_by_ref(ref: '5a3cba405f73778b487d56fad3fd4083cfb112b5', semver: '1.0.0')).to eq('1.1.0') end - it "should correctly increment major so version becomes 2.0.0" do - expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: '1.0.0')).to eq("2.0.0") + it 'should correctly increment major so version becomes 2.0.0' do + expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: '1.0.0')).to eq('2.0.0') end - it "should correctly increment major so new semver v2.0.0" do - expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: 'v1.0.0')).to eq("v2.0.0") + it 'should correctly increment major so new semver v2.0.0' do + expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: 'v1.0.0')).to eq('v2.0.0') end - end context '--semver and --prefix specified in ref' do - it "should correctly increment major so new semver v2.0.0 with manually added prefix" do - expect(PlusBump.bump_by_ref(ref: "e318c48368febb79309e7c371d99bb49fdd5f900", semver: '1.0.0', prefix: 'v')).to eq("v2.0.0") - end + it 'should correctly increment major so new semver v2.0.0 with manually added prefix' do + expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: '1.0.0', prefix: 'v')).to eq('v2.0.0') + end end context 'tag command used' do - - it "should increment to major when used against 0.1.* and not be 0.1.0" do - expect(PlusBump.bump_by_tag(latest: "0.1.")).not_to eq("0.1.0") + it 'should increment to major when used against 0.1.* and not be 0.1.0' do + expect(PlusBump.bump_by_tag(latest: '0.1.')).not_to eq('0.1.0') end - it "should increment to major when used against 0.1.*" do - expect(PlusBump.bump_by_tag(latest: "0.1.")).to eq("1.0.0") - end - it "should increment to 1.0.0 when no tag found" do - expect(PlusBump.bump_by_tag(latest: "not_found")).to eq("1.0.0") + it 'should increment to major when used against 0.1.*' do + expect(PlusBump.bump_by_tag(latest: '0.1.')).to eq('1.0.0') end - it "should incremment to 3.0.0 when semver is prefix" do - expect(PlusBump.bump_by_tag(latest: "[0-9]")).to eq("3.0.0") + it 'should increment to 1.0.0 when no tag found' do + expect(PlusBump.bump_by_tag(latest: 'not_found')).to eq('1.0.0') end - end - - context 'tag command used with --prefix switch' do - it "should incremment to 3.0.0 when semver is prefix, and append prefix if specifed" do - expect(PlusBump.bump_by_tag(latest: "[0-9]", prefix: 'v')).to eq("v3.0.0") + it 'should incremment to 3.0.0 when semver is prefix' do + expect(PlusBump.bump_by_tag(latest: '[0-9]')).to eq('3.0.0') end + end - it "should increment to correctly with tag prefix" do - expect(PlusBump.bump_by_tag(latest: "R_", prefix: 'R_')).to eq("R_2.1.0") - end + context 'tag command used with --prefix switch' do + it 'should incremment to 3.0.0 when semver is prefix, and append prefix if specifed' do + expect(PlusBump.bump_by_tag(latest: '[0-9]', prefix: 'Test_')).to eq('Test_3.0.0') + end + it 'should increment to correctly with tag prefix' do + expect(PlusBump.bump_by_tag(latest: 'R_', prefix: 'Test_')).to eq('Test_2.1.0') + end end - context 'tag should be created' do - specify { expect { PlusBump::Tag.create("1.0.0") }.to output(/Created tag 1.0.0/).to_stdout } + context 'tag should be created' do + specify { expect { PlusBump::Tag.create('Test_1.0.0') }.to output(/Created tag Test_1.0.0/).to_stdout } end - context 'console response behaviour' do - specify { expect { puts PlusBump.bump_by_tag(latest: "R_", prefix: 'R_') }.to output(/R_2.1.0/).to_stdout } - specify { expect { puts PlusBump.bump_by_tag(latest: "R_") }.to output(/2.1.0/).to_stdout } - specify { expect { PlusBump.bump_by_tag(latest: "not_found") }.to output(/No matching tag found for not_found/).to_stdout } + context 'console response behaviour' do + specify { expect { puts PlusBump.bump_by_tag(latest: 'R_', prefix: 'R_') }.to output(/R_2.1.0/).to_stdout } + specify { expect { puts PlusBump.bump_by_tag(latest: 'R_') }.to output(/2.1.0/).to_stdout } + specify { expect { PlusBump.bump_by_tag(latest: 'not_found') }.to output(/No matching tag found for not_found/).to_stdout } specify { expect(`ruby bin/plusbump -blaha`).to match(/Usage:/) } end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 251aa51..0cb0392 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,58 +43,4 @@ # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end end From d4cbb5fb44f90b1bb35b350f3fdc513906c7c30c Mon Sep 17 00:00:00 2001 From: Mads Nielsen Date: Wed, 20 Feb 2019 15:48:29 +0100 Subject: [PATCH 3/5] New DocOpt Usage string. DocOpt updated to describe the intended v2.0 behaviour. --- bin/plusbump | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/bin/plusbump b/bin/plusbump index 8166a72..a43dd55 100755 --- a/bin/plusbump +++ b/bin/plusbump @@ -3,44 +3,37 @@ require 'docopt' require 'plusbump' doc = < [options] - plusbump tag [] [options] plusbump --version - -Commands: - ref: - Bumps using a git ref as a base. - tag: - Bumps using tags, uses glob patterns to list tags matching, and selects the latest - -Arguments: - A git reference. If specified, PlusBump will search for bumps from HEAD back to this instead of searching for a tag. - The base semver version to use as a base when outputting the bumped version. - Git glob pattern tags must match for eligability. The resulting version number tries to filter out the tag glob from the result. - - Examples: - Numeric tag: '[0-9]', captures: 1.0.0, 2.0.0 - Version tag: 'v', captures: v1.0.0, v2.0.0 + plusbump --from-ref --base-version= + plusbump --from-tag --base-version= [--new-prefix=] [--create-tag] + plusbump --from-tag --base-version-from-tag= [--new-prefix=] [--create-tag] Options: - -h --help Show this screen. + -h --help Show this screen. + --version Shows current version of PlusBump + -d --debug Debug flag - -t --create-tag + --from-ref Specify a git ref (tree'ish) to use as start of commit interval. + PlusBump will search for bump declarations from HEAD back to, but not including this ref. - Tags the current commit with the result of the bump operation + --from-tag Specify a glob pattern (same as git tag -l ). PlusBump will find the latest tag matching this pattern + and use as the start of commit interval to analyse. - -p --prefix= + --base-version= Take semver version as argument and use as base for computed new version + --base-version-from-tag= Find semver base version from the found tag. Optionally strip a prefix (e.g. "R_"). [default: ""] - Specify the prefix for the new tag name. By default we do not include prefixes in the result. + --new-prefix= Optionally specify a prefix for the output computed SemVer. (e.g. "R_", or "WOULD_BE_"). - -s --start-ref= + --create-tag PlusBump tags the HEAD commit with the computed new SemVer (incl. optional prefix). This will not do a "git push". - Indicates where the search should start. By default we use 'HEAD' as a starting point. - - --version Shows current version of PlusBump - --debug Debug flag + # --majorpattern= + # --minorpattern= + # --patchpattern= DOCOPT From 5073edfd0ba7e5ef068ded25e39b762cf23f1d6c Mon Sep 17 00:00:00 2001 From: Mads Nielsen Date: Wed, 20 Feb 2019 17:28:37 +0100 Subject: [PATCH 4/5] Rewrote test with DocOpt parsing --- bin/plusbump | 44 +------------------ lib/plusbump.rb | 15 +++++-- lib/plusbump/usage.rb | 36 +++++++++++++++ pkg/plusbump-2.0.0.beta.gem | Bin 9216 -> 0 bytes spec/plusbump_spec.rb | 85 ++++++++++++++++++++++-------------- 5 files changed, 101 insertions(+), 79 deletions(-) create mode 100644 lib/plusbump/usage.rb delete mode 100644 pkg/plusbump-2.0.0.beta.gem diff --git a/bin/plusbump b/bin/plusbump index a43dd55..13e0dc4 100755 --- a/bin/plusbump +++ b/bin/plusbump @@ -2,54 +2,14 @@ require 'docopt' require 'plusbump' -doc = < --base-version= - plusbump --from-tag --base-version= [--new-prefix=] [--create-tag] - plusbump --from-tag --base-version-from-tag= [--new-prefix=] [--create-tag] - -Options: - -h --help Show this screen. - --version Shows current version of PlusBump - -d --debug Debug flag - - --from-ref Specify a git ref (tree'ish) to use as start of commit interval. - PlusBump will search for bump declarations from HEAD back to, but not including this ref. - - --from-tag Specify a glob pattern (same as git tag -l ). PlusBump will find the latest tag matching this pattern - and use as the start of commit interval to analyse. - - --base-version= Take semver version as argument and use as base for computed new version - --base-version-from-tag= Find semver base version from the found tag. Optionally strip a prefix (e.g. "R_"). [default: ""] - - --new-prefix= Optionally specify a prefix for the output computed SemVer. (e.g. "R_", or "WOULD_BE_"). - - --create-tag PlusBump tags the HEAD commit with the computed new SemVer (incl. optional prefix). This will not do a "git push". - - # --majorpattern= - # --minorpattern= - # --patchpattern= - -DOCOPT - -# Note: If you are reading the above usage in the source code and not using --help, -# then ignore the double escapes in the usage examples. -# On the command line you have to write --majorpattern='\+major' -# The extra escape is to make it print that way in the usage message. - begin # Parse Commandline Arguments - input = Docopt.docopt(doc, version: PlusBump::VERSION) + input = Docopt.docopt(PlusBump::DOCOPT, version: PlusBump::VERSION) puts input if input['--debug'] rescue Docopt::Exit => e puts e.message exit end -result = PlusBump.run(input) +result = PlusBump.bump(input) PlusBump::Tag.create(result) if input['--create-tag'] && result diff --git a/lib/plusbump.rb b/lib/plusbump.rb index 99cf80f..b45f905 100644 --- a/lib/plusbump.rb +++ b/lib/plusbump.rb @@ -1,9 +1,11 @@ require 'plusbump/version' +require 'plusbump/usage' require 'semver' require 'rugged' # PlusBump main module module PlusBump + # Module defaults BASE = '0.0.0' MAJOR = '+major' @@ -38,7 +40,7 @@ def self.extract_prefix(partial) /\D+/.match(partial)[0] if /\D+/ =~ partial end - def self.run(input) + def self.bump(input) if input['tag'] bump_by_tag(latest: input[''], prefix: input['--prefix'], debug: input['--debug']) elsif input['ref'] @@ -76,6 +78,12 @@ def self.bump_by_ref(args = {}) final_res = prefix + (result.format "%M.%m.%p%s") end + # Should return a Rugged::Tag object + def self.find_newest_matching_tag(candidates) + candidates.sort! { |a,b| a.target.time <=> b.target.time } + candidates.last + end + def self.bump_by_tag(args = {}) base = '0.0.0' # Init Repo from current directory @@ -90,14 +98,13 @@ def self.bump_by_tag(args = {}) if candidates.empty? puts 'No matching tag found for ' + args[:latest] else - candidates.sort! { |a,b| a.target.time <=> b.target.time } - latest_match = candidates.last + latest_match = find_newest_matching_tag(candidates) # Set target of matching commit as the tail of our walker w.hide(latest_match.target) base = latest_match.name.sub(args[:latest],'') puts "Found matching tag #{latest_match.name}" if args[:debug] end - + v_number = base.split('.') # v_special = base.split('-') prefix = args[:prefix] || '' diff --git a/lib/plusbump/usage.rb b/lib/plusbump/usage.rb new file mode 100644 index 0000000..20b2656 --- /dev/null +++ b/lib/plusbump/usage.rb @@ -0,0 +1,36 @@ +module PlusBump + DOCOPT = < --base-version= [options] + plusbump --from-tag --base-version= [--new-prefix=] [--create-tag] [options] + plusbump --from-tag --base-version-from-tag= [--new-prefix=] [--create-tag] [options] + +Options: + -h --help Show this screen. + --version Shows current version of PlusBump + -d --debug Debug flag + + --from-ref Specify a git ref (tree'ish) to use as start of commit interval. + PlusBump will search for bump declarations from HEAD back to, but not including this ref. + + --from-tag Specify a glob pattern (same as git tag -l ). PlusBump will find the latest tag matching this pattern + and use as the start of commit interval to analyse. + + --base-version= Take semver version as argument and use as base for computed new version + --base-version-from-tag= Find semver base version from the found tag. Optionally strip a prefix (e.g. "R_"). [default: ""] + + --new-prefix= Optionally specify a prefix for the output computed SemVer. (e.g. "R_", or "WOULD_BE_"). + + --create-tag PlusBump tags the HEAD commit with the computed new SemVer (incl. optional prefix). This will not do a "git push". + + # --majorpattern= + # --minorpattern= + # --patchpattern= +DOCOPT + +end diff --git a/pkg/plusbump-2.0.0.beta.gem b/pkg/plusbump-2.0.0.beta.gem deleted file mode 100644 index 083344c0d7400f1e0b0631e9e9026c8b5bf69b52..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9216 zcmeHsRa6|x+GV4`-Q9!JNbumHfyP~fy9L+a8r&@e3vLYr0tC`{1Hl6XY21Qa@IX)Q z%)|ZHd6;>+XYRxKUdmQgec!ICUA1<(+Im~sSbAIX+6MyuQwIEFLPA1-f2DuyuPMKv zkO+WZP*6k|$j>jr&kq3psSy$cFaZBk4*kz@eZ0IaJ^#4m=U{8=@;@8?lK+3T|DV|Y z9o%2K|F;(D6EFZH#J48MD02oT8p}YEkekM{`UN?fw7ukxgd_vHoHKZd{zk^YtDH0-r zN=UU#O~GW-9CgWIkNKE>jjZ}1GDgy)+`QOTuk@h3MM(}bdLk1 zk1hexn;d+!FNrlJG#M34+TEgF0a(auNQBF8HLxI3Tx_Q61k#~t=|PDUY>_{@dy7Tj zWy>+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)eP1#V^Mx)A3R&C{zVzDPCN@gvXd_zU>kFT1(EE-W%Cl?%Z^#3zhf!>nd2V>{z2d$ J1pZb8{udm#)I$IO diff --git a/spec/plusbump_spec.rb b/spec/plusbump_spec.rb index e13ad6c..d7a5c54 100644 --- a/spec/plusbump_spec.rb +++ b/spec/plusbump_spec.rb @@ -1,60 +1,86 @@ require 'plusbump' +require 'docopt' RSpec.configure do |config| - config.before(:all) do + config.before(:all) do PlusBump::Tag.delete('Test_1.0.0') end end -RSpec.describe PlusBump, "#bump" do - context 'ref command used' do +def build_input(commandline) + Docopt.docopt(PlusBump::DOCOPT, version: PlusBump::VERSION, argv: commandline.split(' ')) +end + +RSpec.describe PlusBump, "bump" do + + context 'testing' do + input = build_input("--from-ref 4343 --base-version=1.0.0 --debug") + end + + context '--from-ref used' do it 'should correctly increment minor to 0.1.0' do - expect(PlusBump.bump_by_ref(ref: '5a3cba405f73778b487d56fad3fd4083cfb112b5')).to eq('0.1.0') + input = build_input("--from-ref 5a3cba405f73778b487d56fad3fd4083cfb112b5 --base-version 0.0.0") + expect(PlusBump.bump(input)).to eq('0.1.0') end - it 'should increment major from first commit' do - expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900')).to eq('1.0.0') + it 'should increment major from to 1.0.0' do + input = build_input("--from-ref e318c48368febb79309e7c371d99bb49fdd5f900 --base-version 0.0.0") + expect(PlusBump.bump(input)).to eq('1.0.0') end end - - context '--semver specifed in ref' do + + context '--base-version used with --from-ref' do it 'should correctly increment minor so version becomes 1.1.0' do - expect(PlusBump.bump_by_ref(ref: '5a3cba405f73778b487d56fad3fd4083cfb112b5', semver: '1.0.0')).to eq('1.1.0') + input = build_input("--from-ref 5a3cba405f73778b487d56fad3fd4083cfb112b5 --base-version 1.0.0") + expect(PlusBump.bump(input)).to eq('1.1.0') end it 'should correctly increment major so version becomes 2.0.0' do - expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: '1.0.0')).to eq('2.0.0') + input = build_input("--from-ref e318c48368febb79309e7c371d99bb49fdd5f900 --base-version 1.0.0") + expect(PlusBump.bump(input)).to eq('2.0.0') end - it 'should correctly increment major so new semver v2.0.0' do - expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: 'v1.0.0')).to eq('v2.0.0') - end - end - context '--semver and --prefix specified in ref' do - it 'should correctly increment major so new semver v2.0.0 with manually added prefix' do - expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: '1.0.0', prefix: 'v')).to eq('v2.0.0') + it 'should correctly increment major output becmes v2.0.0' do + input = build_input("--from-ref e318c48368febb79309e7c371d99bb49fdd5f900 --base-version 1.0.0 --new-prefix=v") + expect(PlusBump.bump(input)).to eq('v2.0.0') end end - context 'tag command used' do +# context '--semver and --prefix specified in ref' do +# it 'should correctly increment major so new semver v2.0.0 with manually added prefix' do +# expect(PlusBump.bump_by_ref(ref: 'e318c48368febb79309e7c371d99bb49fdd5f900', semver: '1.0.0', prefix: 'v')).to eq('v2.0.0') +# end +# end + + context '--from-tag with --base-version' do it 'should increment to major when used against 0.1.* and not be 0.1.0' do - expect(PlusBump.bump_by_tag(latest: '0.1.')).not_to eq('0.1.0') + input = build_input("--from-tag 0.1. --base-version 0.0.0") + expect(PlusBump.bump(input)).not_to eq('0.1.0') + #expect(PlusBump.bump_by_tag(latest: '0.1.')).not_to eq('0.1.0') end it 'should increment to major when used against 0.1.*' do - expect(PlusBump.bump_by_tag(latest: '0.1.')).to eq('1.0.0') + input = build_input("--from-tag 0.1. --base-version 0.0.0") + expect(PlusBump.bump(input)).not_to eq('0.1.0') + #expect(PlusBump.bump_by_tag(latest: '0.1.')).to eq('1.0.0') end it 'should increment to 1.0.0 when no tag found' do - expect(PlusBump.bump_by_tag(latest: 'not_found')).to eq('1.0.0') + input = build_input("--from-tag not_found --base-version 0.0.0") + pending "Did we decide on how to handle tag not found?" end it 'should incremment to 3.0.0 when semver is prefix' do - expect(PlusBump.bump_by_tag(latest: '[0-9]')).to eq('3.0.0') + #expect(PlusBump.bump_by_tag(latest: '[0-9]')).to eq('3.0.0') + pending "This one i don't remember" end end - context 'tag command used with --prefix switch' do - it 'should incremment to 3.0.0 when semver is prefix, and append prefix if specifed' do - expect(PlusBump.bump_by_tag(latest: '[0-9]', prefix: 'Test_')).to eq('Test_3.0.0') + context '--from-tag with with --base-version-from-tag' do + it 'should increment to 3.0.0 when used with 2.0.0 as tag glob' do + input = build_input("--from-tag 2.0.0 --base-version-from-tag='' --new-prefix=Test_") + expect(PlusBump.bump(input)).to eq('Test_3.0.0') + #expect(PlusBump.bump_by_tag(latest: '[0-9]', prefix: 'Test_')).to eq('Test_3.0.0') end it 'should increment to correctly with tag prefix' do - expect(PlusBump.bump_by_tag(latest: 'R_', prefix: 'Test_')).to eq('Test_2.1.0') + input = build_input("--from-tag R_ --base-version-from-tag='R_'") + expect(PlusBump.bump(input)).to eq('2.1.0') + #expect(PlusBump.bump_by_tag(latest: 'R_', prefix: 'Test_')).to eq('2.1.0') end end @@ -62,11 +88,4 @@ specify { expect { PlusBump::Tag.create('Test_1.0.0') }.to output(/Created tag Test_1.0.0/).to_stdout } end - context 'console response behaviour' do - specify { expect { puts PlusBump.bump_by_tag(latest: 'R_', prefix: 'R_') }.to output(/R_2.1.0/).to_stdout } - specify { expect { puts PlusBump.bump_by_tag(latest: 'R_') }.to output(/2.1.0/).to_stdout } - specify { expect { PlusBump.bump_by_tag(latest: 'not_found') }.to output(/No matching tag found for not_found/).to_stdout } - specify { expect(`ruby bin/plusbump -blaha`).to match(/Usage:/) } - end - end From cb9697525c2294201d66d0684413caa7a03bcc72 Mon Sep 17 00:00:00 2001 From: Mads Nielsen Date: Fri, 22 Mar 2019 13:02:29 +0100 Subject: [PATCH 5/5] Updated with the ability to specify patterns for major, minor and patch --- lib/plusbump.rb | 90 +++++++++++++++++++++++++++-------------- lib/plusbump/config.rb | 7 ++++ lib/plusbump/usage.rb | 7 ++-- lib/plusbump/version.rb | 2 +- spec/plusbump_spec.rb | 33 +++++---------- 5 files changed, 81 insertions(+), 58 deletions(-) create mode 100644 lib/plusbump/config.rb diff --git a/lib/plusbump.rb b/lib/plusbump.rb index b45f905..05f47bf 100644 --- a/lib/plusbump.rb +++ b/lib/plusbump.rb @@ -1,16 +1,12 @@ require 'plusbump/version' require 'plusbump/usage' +require 'plusbump/config' require 'semver' require 'rugged' # PlusBump main module module PlusBump - # Module defaults - BASE = '0.0.0' - MAJOR = '+major' - MINOR = '+minor' - PATCH = '+patch' @repo = nil def self.repo @@ -18,7 +14,6 @@ def self.repo @repo end - # Class Tag class Tag def self.create(tag_name) target = PlusBump.repo.head.target @@ -40,11 +35,30 @@ def self.extract_prefix(partial) /\D+/.match(partial)[0] if /\D+/ =~ partial end + def self.transform(input) + Hash.new( input.map { |k,v| + [k.replace('-','').to_s,v] + }) + end + def self.bump(input) - if input['tag'] - bump_by_tag(latest: input[''], prefix: input['--prefix'], debug: input['--debug']) - elsif input['ref'] - bump_by_ref(ref: input[''], semver: input[''], prefix: input['--prefix'], debug: input['--debug']) + if input['--from-tag'] + bump_by_tag(glob: input['--from-tag'], + base: input['--base-version'], + prefix: input['--new-prefix'] || '', + tag_replacement: input['--base-version-from-tag'], + major_pattern: input['--major-pattern'], + minor_pattern: input['--minor-pattern'], + patch_pattern: input['--patch-pattern'], + debug: input['--debug']) + elsif input['--from-ref'] + bump_by_ref(ref: input['--from-ref'], + semver: input['--base-version'], + prefix: input['--new-prefix'] || '', + major_pattern: input['--major-pattern'], + minor_pattern: input['--minor-pattern'], + patch_pattern: input['--patch-pattern'], + debug: input['--debug']) end end @@ -56,26 +70,26 @@ def self.create_walker(repository) w end + # TODO: Need fixing! + def self.current_semver() + + end + def self.bump_by_ref(args = {}) semver_string = args[:semver] || PlusBump::BASE w = create_walker(PlusBump.repo) tail = PlusBump.repo.rev_parse(args[:ref]) w.hide(tail) - prefix = args[:prefix] || '' v_number = semver_string.split('.') v_special = semver_string.split('-').size > 1 ? semver_string.split('-')[-1] : '' - if prefix.empty? - prefix = extract_prefix(v_number[0]) || '' - end - # Current semver string result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, v_special) # TODO: Fix special # Logic bump - bump_action(w, result) - final_res = prefix + (result.format "%M.%m.%p%s") + bump_action(w, result, major_p: args[:major_pattern], minor_p: args[:minor_pattern], patch_p: args[:patch_pattern]) + final_res = extract_prefix(v_number[0]) || '' + (result.format "%M.%m.%p%s") end # Should return a Rugged::Tag object @@ -84,6 +98,17 @@ def self.find_newest_matching_tag(candidates) candidates.last end + # The justification for this method is to split a semver tag into it's composite parts. Major.Minor.Patch[+-].... + # We need these parts to construct the SemVer object + def self.parse_semver_parts(base) + main = base.split(/[\+\-]/) # Should split something like Release_1.2.3-beta1+001 into two parts. + version_part = main[0].split('.') + # Clean up the version part...extract all numbers excluding non-numerical characters + version_part.map! { |elem| extract_number(elem) } + special_part = main[1..-1] || '' + return { :version_part => version_part, :special_part => special_part.join('') } + end + def self.bump_by_tag(args = {}) base = '0.0.0' # Init Repo from current directory @@ -91,36 +116,39 @@ def self.bump_by_tag(args = {}) w = create_walker(PlusBump.repo) head = PlusBump.repo.lookup(PlusBump.repo.head.target.oid) candidates = [] - tagcollection.each(args[:latest] + '*') do |tag| + tagcollection.each(args[:glob] + '*') do |tag| candidates << tag if !PlusBump.repo.merge_base(tag.target, head).nil? end if candidates.empty? - puts 'No matching tag found for ' + args[:latest] + puts 'No matching tag found for ' + args[:glob] else latest_match = find_newest_matching_tag(candidates) # Set target of matching commit as the tail of our walker w.hide(latest_match.target) - base = latest_match.name.sub(args[:latest],'') + base = latest_match.name puts "Found matching tag #{latest_match.name}" if args[:debug] end - v_number = base.split('.') - # v_special = base.split('-') - prefix = args[:prefix] || '' - # Current semver string - result = SemVer.new(extract_number(v_number[0]).to_i, v_number[1].to_i, v_number[2].to_i, '') # TODO: FIX SPECIAL + unless args[:tag_replacement].nil? + replacer = args[:tag_replacement] || '' + parts = parse_semver_parts(base) + result = SemVer.new(parts[:version_part][0].sub(replacer, '').to_i, parts[:version_part][1].to_i, parts[:version_part][2].to_i, parts[:special_part]) + else + parts = parse_semver_parts(args[:base]) + result = SemVer.new(parts[:version_part][0].to_i, parts[:version_part][1].to_i, parts[:version_part][2].to_i, parts[:special_part]) # TODO: FIX SPECIAL + end # Logic bumps - bump_action(w, result) - prefix + (result.format "%M.%m.%p%s") + bump_action(w, result, major_p: args[:major_pattern], minor_p: args[:minor_pattern], patch_p: args[:patch_pattern]) + args[:prefix] + (result.format "%M.%m.%p%s") end - def self.bump_action(walker, semver) + def self.bump_action(walker, semver, **args) # Defaults - major = /\+major/ - minor = /\+minor/ - patch = /\+patch/ + major = Regexp.new(Regexp.quote(args[:major_p] || PlusBump::MAJOR)) + minor = Regexp.new(Regexp.quote(args[:minor_p] || PlusBump::MINOR)) + patch = Regexp.new(Regexp.quote(args[:patch_p] || PlusBump::PATCH)) minor_bump = false walker.each do |commit| diff --git a/lib/plusbump/config.rb b/lib/plusbump/config.rb new file mode 100644 index 0000000..37b0184 --- /dev/null +++ b/lib/plusbump/config.rb @@ -0,0 +1,7 @@ +module PlusBump + # Module defaults + BASE = '0.0.0' + MAJOR = ENV['plusbump_major'] || '+major' + MINOR = ENV['plusbump_minor'] || '+minor' + PATCH = ENV['plusbump_patch'] || '+patch' +end diff --git a/lib/plusbump/usage.rb b/lib/plusbump/usage.rb index 20b2656..8ffbb78 100644 --- a/lib/plusbump/usage.rb +++ b/lib/plusbump/usage.rb @@ -24,13 +24,14 @@ module PlusBump --base-version= Take semver version as argument and use as base for computed new version --base-version-from-tag= Find semver base version from the found tag. Optionally strip a prefix (e.g. "R_"). [default: ""] + --new-prefix= Optionally specify a prefix for the output computed SemVer. (e.g. "R_", or "WOULD_BE_"). --create-tag PlusBump tags the HEAD commit with the computed new SemVer (incl. optional prefix). This will not do a "git push". - # --majorpattern= - # --minorpattern= - # --patchpattern= + --patch-pattern= Specify regex pattern for bumping patch version + --minor-pattern= Specify regex pattern for bumping minor version + --major-pattern= Specify regex pattern for bumping major version DOCOPT end diff --git a/lib/plusbump/version.rb b/lib/plusbump/version.rb index bfbd69c..b35eb82 100644 --- a/lib/plusbump/version.rb +++ b/lib/plusbump/version.rb @@ -1,3 +1,3 @@ module PlusBump - VERSION = '2.0.0.beta'.freeze + VERSION = '2.0.0.beta2'.freeze end diff --git a/spec/plusbump_spec.rb b/spec/plusbump_spec.rb index d7a5c54..245d216 100644 --- a/spec/plusbump_spec.rb +++ b/spec/plusbump_spec.rb @@ -12,11 +12,6 @@ def build_input(commandline) end RSpec.describe PlusBump, "bump" do - - context 'testing' do - input = build_input("--from-ref 4343 --base-version=1.0.0 --debug") - end - context '--from-ref used' do it 'should correctly increment minor to 0.1.0' do input = build_input("--from-ref 5a3cba405f73778b487d56fad3fd4083cfb112b5 --base-version 0.0.0") @@ -37,11 +32,6 @@ def build_input(commandline) input = build_input("--from-ref e318c48368febb79309e7c371d99bb49fdd5f900 --base-version 1.0.0") expect(PlusBump.bump(input)).to eq('2.0.0') end - - it 'should correctly increment major output becmes v2.0.0' do - input = build_input("--from-ref e318c48368febb79309e7c371d99bb49fdd5f900 --base-version 1.0.0 --new-prefix=v") - expect(PlusBump.bump(input)).to eq('v2.0.0') - end end # context '--semver and --prefix specified in ref' do @@ -54,20 +44,11 @@ def build_input(commandline) it 'should increment to major when used against 0.1.* and not be 0.1.0' do input = build_input("--from-tag 0.1. --base-version 0.0.0") expect(PlusBump.bump(input)).not_to eq('0.1.0') - #expect(PlusBump.bump_by_tag(latest: '0.1.')).not_to eq('0.1.0') end it 'should increment to major when used against 0.1.*' do input = build_input("--from-tag 0.1. --base-version 0.0.0") expect(PlusBump.bump(input)).not_to eq('0.1.0') - #expect(PlusBump.bump_by_tag(latest: '0.1.')).to eq('1.0.0') - end - it 'should increment to 1.0.0 when no tag found' do - input = build_input("--from-tag not_found --base-version 0.0.0") - pending "Did we decide on how to handle tag not found?" - end - it 'should incremment to 3.0.0 when semver is prefix' do - #expect(PlusBump.bump_by_tag(latest: '[0-9]')).to eq('3.0.0') - pending "This one i don't remember" + expect(PlusBump.bump(input)).to eq('1.0.0') end end @@ -75,12 +56,18 @@ def build_input(commandline) it 'should increment to 3.0.0 when used with 2.0.0 as tag glob' do input = build_input("--from-tag 2.0.0 --base-version-from-tag='' --new-prefix=Test_") expect(PlusBump.bump(input)).to eq('Test_3.0.0') - #expect(PlusBump.bump_by_tag(latest: '[0-9]', prefix: 'Test_')).to eq('Test_3.0.0') + end + it 'should increment to 2.1.0 when used with 2.0.0 as tag glob and no matching major pattern (minor matches)' do + input = build_input("--from-tag 2.0.0 --base-version-from-tag='' --new-prefix=Test_ --major-pattern=not_there") + expect(PlusBump.bump(input)).to eq('Test_2.1.0') end it 'should increment to correctly with tag prefix' do - input = build_input("--from-tag R_ --base-version-from-tag='R_'") + input = build_input("--from-tag R_ --base-version-from-tag=R_") + expect(PlusBump.bump(input)).to eq('2.1.0') + end + it 'should increment correctly with empty base-version-from-tag' do + input = build_input("--from-tag R_ --base-version-from-tag=''") expect(PlusBump.bump(input)).to eq('2.1.0') - #expect(PlusBump.bump_by_tag(latest: 'R_', prefix: 'Test_')).to eq('2.1.0') end end