class Tagging::AppVersion

Public Class Methods

init_version_file() click to toggle source
# File lib/tagging/app_version.rb, line 28
def self.init_version_file
  initial_version = 'v0.0.1-00'
end
new(options={}) click to toggle source
# File lib/tagging/app_version.rb, line 7
def initialize(options={})
  @options = {message:'versioning by CI'}.merge(options)
  @git = nil
end
version_format_valid?(v='') click to toggle source
# File lib/tagging/app_version.rb, line 24
def self.version_format_valid?(v='')
  (v && v =~ /^v\d+\.\d+\.\d+-[\.\d+]+$/)
end

Public Instance Methods

commit_and_push(project_directory=Dir.pwd) click to toggle source
# File lib/tagging/app_version.rb, line 50
def commit_and_push(project_directory=Dir.pwd)
  @git = Git.open(project_directory, :log=>Logger.new(STDOUT))
  
  set_global_config

  @git.add_tag(self.version, nil, message: @options[:message])
  @git.push('origin', "refs/tags/#{self.version}")
end
increment_and_push() click to toggle source
# File lib/tagging/app_version.rb, line 32
def increment_and_push
  load_tags
  increment_version
  commit_and_push
end
increment_version() click to toggle source
# File lib/tagging/app_version.rb, line 38
def increment_version
  @options[:current_version] = self.version.next
end
load_tags() click to toggle source
# File lib/tagging/app_version.rb, line 19
def load_tags
  puts "git -C #{Dir.pwd} fetch --tags" 
  `git -C #{Dir.pwd} fetch --tags`
end
set_global_config() click to toggle source
# File lib/tagging/app_version.rb, line 42
def set_global_config
  if @options[:config]
    @options[:config].each do |key, value|
      @git.config(key, value)
    end
  end
end
version() click to toggle source
# File lib/tagging/app_version.rb, line 12
def version
  load_tags if @options[:load_tags]
  @options[:current_version] ||= `git -C #{Dir.pwd} describe --tags $(git -C #{Dir.pwd} for-each-ref refs/tags --sort=-taggerdate --format='%(objectname)' --count=1)`.chomp
  @options[:current_version] = self.class.init_version_file unless self.class.version_format_valid?(@options[:current_version])
  @options[:current_version]
end