Class: Tagging::AppVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/tagging/app_version.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AppVersion

Returns a new instance of AppVersion.



7
8
9
10
# File 'lib/tagging/app_version.rb', line 7

def initialize(options={})
  @options = {message:'versioning by CI'}.merge(options)
  @git = nil
end

Class Method Details

.init_version_fileObject



28
29
30
# File 'lib/tagging/app_version.rb', line 28

def self.init_version_file
  initial_version = 'v0.0.1-00'
end

.version_format_valid?(v = '') ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tagging/app_version.rb', line 24

def self.version_format_valid?(v='')
  (v && v =~ /^v\d+\.\d+\.\d+-[\.\d+]+$/)
end

Instance Method Details

#commit_and_push(project_directory = Dir.pwd) ⇒ Object



50
51
52
53
54
55
56
57
# 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_pushObject



32
33
34
35
36
# File 'lib/tagging/app_version.rb', line 32

def increment_and_push
  load_tags
  increment_version
  commit_and_push
end

#increment_versionObject



38
39
40
# File 'lib/tagging/app_version.rb', line 38

def increment_version
  @options[:current_version] = self.version.next
end

#load_tagsObject



19
20
21
22
# 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_configObject



42
43
44
45
46
47
48
# 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

#versionObject



12
13
14
15
16
17
# 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