Class: Tagging::AppVersion
- Inherits:
-
Object
- Object
- Tagging::AppVersion
- Defined in:
- lib/tagging/app_version.rb
Class Method Summary collapse
Instance Method Summary collapse
- #commit_and_push(project_directory = Dir.pwd) ⇒ Object
- #increment_and_push ⇒ Object
- #increment_version ⇒ Object
-
#initialize(options = {}) ⇒ AppVersion
constructor
A new instance of AppVersion.
- #load_tags ⇒ Object
- #set_global_config ⇒ Object
- #version ⇒ Object
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 = {message:'versioning by CI'}.merge() @git = nil end |
Class Method Details
.init_version_file ⇒ Object
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
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_push ⇒ Object
32 33 34 35 36 |
# File 'lib/tagging/app_version.rb', line 32 def increment_and_push increment_version commit_and_push end |
#increment_version ⇒ Object
38 39 40 |
# File 'lib/tagging/app_version.rb', line 38 def increment_version @options[:current_version] = self.version.next end |
#load_tags ⇒ Object
19 20 21 22 |
# File 'lib/tagging/app_version.rb', line 19 def puts "git -C #{Dir.pwd} fetch --tags" `git -C #{Dir.pwd} fetch --tags` end |
#set_global_config ⇒ Object
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 |
#version ⇒ Object
12 13 14 15 16 17 |
# File 'lib/tagging/app_version.rb', line 12 def version 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 |