Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Features Related to Build Versions #1

Merged
merged 1 commit into from
Mar 6, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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