Skip to content
Snippets Groups Projects
Commit 07483855 authored by Steven Danna's avatar Steven Danna
Browse files

Merge pull request #446 from chef/ssd/static-version

Respect append_timestamp config when constructing a version number
parents 398b1d8b 6801f8d9
No related branches found
No related tags found
No related merge requests found
Omnibus CHANGELOG
=================
v4.1.0 (Unreleased)
### Bug Fixes
- Config.append_timestamp is now properly handled by the build_version
DSL. For some users, this may introduce a change in behavior. To
revert to the old behavior set append_timestamp to false in
`omnibus.rb` or use --override append_timestamp:false at the command
line.
 
v4.0.0 (December 15, 2014)
--------------------------
Loading
Loading
Loading
Loading
@@ -128,6 +128,11 @@ Some DSL methods available include:
| `package` | Invoke a packager-specific DSL |
| `compress` | Invoke a compressor-specific DSL |
 
By default a timestamp is appended to the build_version. You can turn
this behavior off by setting `append_timestamp` to `false` in your
configuration file or using `--override append_timestamp:false` at the
command line.
For more information, please see the [`Project` documentation](http://rubydoc.info/github/opscode/omnibus/Omnibus/Project).
 
### Software
Loading
Loading
Loading
Loading
@@ -18,6 +18,7 @@ Given(/^I have an omnibus project named "(.+)"$/) do |name|
 
write_file('omnibus.rb', <<-EOH.gsub(/^ {4}/, ''))
# Build configuration
append_timestamp false
cache_dir './local/omnibus/cache'
git_cache_dir './local/omnibus/cache/git_cache'
source_dir './local/omnibus/src'
Loading
Loading
Loading
Loading
@@ -46,6 +46,10 @@ module Omnibus
def semver
new.semver
end
def build_start_time
new.build_start_time
end
end
 
# Create a new BuildVersion
Loading
Loading
@@ -102,7 +106,7 @@ module Omnibus
#
# format: YYYYMMDDHHMMSS example: 20130131123345
if Config.append_timestamp
build_version_items << build_start_time.strftime(TIMESTAMP_FORMAT)
build_version_items << build_start_time
end
 
# We'll append the git describe information unless we are sitting right
Loading
Loading
@@ -120,6 +124,26 @@ module Omnibus
build_tag
end
 
# We'll attempt to retrive the timestamp from the Jenkin's set BUILD_ID
# environment variable. This will ensure platform specfic packages for the
# same build will share the same timestamp.
def build_start_time
@build_start_time ||= begin
if ENV['BUILD_ID']
begin
Time.strptime(ENV['BUILD_ID'], '%Y-%m-%d_%H-%M-%S')
rescue ArgumentError
error_message = 'BUILD_ID environment variable '
error_message << 'should be in YYYY-MM-DD_hh-mm-ss '
error_message << 'format.'
raise ArgumentError, error_message
end
else
Time.now.utc
end
end.strftime(TIMESTAMP_FORMAT)
end
# Generates a version string by running
# {https://www.kernel.org/pub/software/scm/git/docs/git-describe.html
# git describe} in the root of the Omnibus project.
Loading
Loading
@@ -237,26 +261,6 @@ module Omnibus
 
private
 
# We'll attempt to retrive the timestamp from the Jenkin's set BUILD_ID
# environment variable. This will ensure platform specfic packages for the
# same build will share the same timestamp.
def build_start_time
@build_start_time ||= begin
if ENV['BUILD_ID']
begin
Time.strptime(ENV['BUILD_ID'], '%Y-%m-%d_%H-%M-%S')
rescue ArgumentError
error_message = 'BUILD_ID environment variable '
error_message << 'should be in YYYY-MM-DD_hh-mm-ss '
error_message << 'format.'
raise ArgumentError, error_message
end
else
Time.now.utc
end
end
end
# Pulls out the major, minor, and patch components from the output
# of {#git_describe}.
#
Loading
Loading
Loading
Loading
@@ -14,6 +14,8 @@
# limitations under the License.
#
 
require 'time'
module Omnibus
class BuildVersionDSL
include Logging
Loading
Loading
@@ -33,7 +35,7 @@ module Omnibus
@output_method = nil
 
if version_string
@build_version = version_string
self.build_version = version_string
elsif block_given?
instance_eval(&block)
construct_build_version unless from_dependency?
Loading
Loading
@@ -78,7 +80,7 @@ module Omnibus
# @return [String]
def explain
if build_version
"Build Version: #{@build_version}"
"Build Version: #{build_version}"
else
if from_dependency?
"Build Version will be determined from software '#{version_dependency}'"
Loading
Loading
@@ -105,6 +107,43 @@ module Omnibus
source_options[:from_dependency]
end
 
def build_version=(new_version)
@build_version = maybe_append_timestamp(new_version)
end
# Append the build_start_time to the given string if
# Config.append_timestamp is true
#
# @param [String] version
# @return [String]
def maybe_append_timestamp(version)
if Config.append_timestamp && !has_timestamp?(version)
[version, Omnibus::BuildVersion.build_start_time].join("+")
else
version
end
end
# Returns true if a given version string Looks like it was already
# created with a function that added a timestamp. The goal of this
# is to avoid breaking all of the people who are currently using
# BuildVersion.semver to create dates.
#
# @param [String] version
# @return [Boolean]
def has_timestamp?(version)
_ver, build_info = version.split('+')
return false if build_info.nil?
build_info.split('.').any? do |part|
begin
Time.strptime(part, Omnibus::BuildVersion::TIMESTAMP_FORMAT)
true
rescue ArgumentError
false
end
end
end
# Determines the build_version based on source_type, output_method.
#
# @param version_source [Omnibus::Software] Software object from which the
Loading
Loading
@@ -120,10 +159,10 @@ module Omnibus
end
 
output = output_method || :semver
@build_version = version.send(output)
self.build_version = version.send(output)
when :version
if version_source
@build_version = version_source.version
self.build_version = version_source.version
else
raise "Please tell me the source to get the version from"
end
Loading
Loading
Loading
Loading
@@ -55,6 +55,7 @@ RSpec.configure do |config|
 
# Reset config
Omnibus.reset!
Omnibus::Config.append_timestamp(false)
 
# Clear the tmp_path on each run
FileUtils.rm_rf(tmp_path)
Loading
Loading
Loading
Loading
@@ -7,8 +7,9 @@ module Omnibus
 
let(:version_string) { "1.0.0" }
let(:description) { nil }
let(:today_string) { Time.now.utc.strftime(Omnibus::BuildVersion::TIMESTAMP_FORMAT) }
 
let(:zoo_version) { double("BuildVersion", semver: "5.5.5", custom: "7.7.7") }
let(:zoo_version) { double("BuildVersion", semver: "5.5.5", custom: "7.7.7", build_start_time: today_string) }
let(:zoo_software) { double("software", name: 'zoo', project_dir: '/etc/zoo', version: "6.6.6") }
 
describe "when given nil" do
Loading
Loading
@@ -23,6 +24,32 @@ module Omnibus
end
end
 
describe "when Config.append_timestamp is true" do
let(:description) do
proc do
source(:git, from_dependency: 'zoo')
end
end
before { Config.append_timestamp(true) }
it "appends a timestamp to a static (String) version" do
expect(subject_with_version.build_version).to eq("1.0.0+#{today_string}")
end
it "doesn't append timestamp to something that already looks like it has a timestamp" do
semver = "1.0.0+#{today_string}.git.222.694b062"
expect(described_class.new(semver).build_version).to eq("1.0.0+#{today_string}.git.222.694b062")
end
it "appends a timestamp to a DSL-built version" do
allow(BuildVersion).to receive(:new).and_return(BuildVersion.new)
allow(BuildVersion).to receive(:new).with("/etc/zoo").and_return(zoo_version)
subject_with_description.resolve(zoo_software)
expect(subject_with_description.build_version).to eq("5.5.5+#{today_string}")
end
end
describe "when given a :git source" do
describe "when given a software as source" do
let(:description) do
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ module Omnibus
subject(:build_version) { described_class.new }
 
before do
Config.append_timestamp(true)
allow_any_instance_of(described_class).to receive(:shellout)
.and_return(double('ouput', stdout: git_describe, exitstatus: 0))
end
Loading
Loading
@@ -139,7 +140,6 @@ module Omnibus
 
describe 'appending a timestamp' do
let(:git_describe) { '11.0.0-alpha-3-207-g694b062' }
context 'by default' do
it 'appends a timestamp' do
expect(build_version.semver).to match(/11.0.0-alpha.3\+#{today_string}[0-9]+.git.207.694b062/)
Loading
Loading
@@ -147,8 +147,6 @@ module Omnibus
end
 
context 'when Config.append_timestamp is true' do
before { Config.append_timestamp(true) }
it 'appends a timestamp' do
expect(build_version.semver).to match(/11.0.0-alpha.3\+#{today_string}[0-9]+.git.207.694b062/)
end
Loading
Loading
@@ -156,7 +154,6 @@ module Omnibus
 
context 'when Config.append_timestamp is false' do
before { Config.append_timestamp(false) }
it 'does not append a timestamp' do
expect(build_version.semver).to match(/11.0.0-alpha.3\+git.207.694b062/)
end
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ module Omnibus
end
 
before do
Config.reset!
# Don't expand paths on the build system. Otherwise, you will end up with
# paths like +\\Users\\you\\Development\\omnibus-ruby\\C:/omnibus-ruby+
# when testing on "other" operating systems
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment