Skip to content

Commit

Permalink
build version helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Delano committed Mar 6, 2012
1 parent c0ac486 commit 4165168
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
12 changes: 1 addition & 11 deletions lib/omnibus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require 'omnibus/s3_tasks'
require 'omnibus/health_check'
require 'omnibus/clean_tasks'
require 'omnibus/build_version'

module Omnibus

Expand All @@ -26,17 +27,6 @@ def self.root
@root
end

def self.build_version
@build_version ||= begin
git_cmd = "git describe"
shell = Mixlib::ShellOut.new(git_cmd,
:cwd => Omnibus.root)
shell.run_command
shell.error!
shell.stdout.chomp
end
end

def self.gem_root=(root)
@gem_root = root
end
Expand Down
49 changes: 49 additions & 0 deletions lib/omnibus/build_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Omnibus
module BuildVersion

def self.full
build_version
end

def self.version_tag
major, minor, patch = version_composition
"#{major}.#{minor}.#{patch}"
end

def self.git_sha
sha_regexp = /g([0-9a-f]+)$/
match = sha_regexp.match(build_version)
match ? match[1] : nil
end

def self.commits_since_tag
commits_regexp = /^\d+\.\d+\.\d+\-(\d+)\-g[0-9a-f]+$/
match = commits_regexp.match(build_version)
match ? match[1].to_i : 0
end

def self.development_version?
major, minor, patch = version_composition
patch.to_i.odd?
end

private

def self.build_version
@build_version ||= begin
git_cmd = "git describe"
shell = Mixlib::ShellOut.new(git_cmd,
:cwd => Omnibus.root)
shell.run_command
shell.error!
shell.stdout.chomp
end
end

def self.version_composition
version_regexp = /^(\d+)\.(\d+)\.(\d+)/
version_regexp.match(build_version)[1..3]
end

end
end
2 changes: 1 addition & 1 deletion lib/omnibus/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def config
end

def build_version
Omnibus.build_version
Omnibus::BuildVersion.full
end

def package_scripts_path
Expand Down

0 comments on commit 4165168

Please sign in to comment.