Commit 4bf1682c authored by itsuugo's avatar itsuugo
Browse files

Add fallback to BUILD_TIMESTAMP



This patchs adds a fallback to the previous behavior in case
BUILD_TIMESTAMP variable is not set to don't break backwards
compatibility.

The current behaviour is as follow:

Check if BUILD_TIMESTAMP is set and use it if it's valid or ...
check if BUILD_ID is set and use it if it's a valid timestamp

If the timestamp is not valid it fails.

Signed-off-by: default avataritsuugo <antonio.ojea.garcia@gmail.com>
parent b7c0455e
......@@ -125,8 +125,8 @@ module Omnibus
end
# We'll attempt to retrieve the timestamp from the Jenkin's set BUILD_TIMESTAMP
# environment variable. This will ensure platform specfic packages for the
# same build will share the same timestamp.
# or fall back to 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_TIMESTAMP"]
......@@ -138,6 +138,15 @@ module Omnibus
error_message << "format."
raise ArgumentError, error_message
end
elsif 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
......
......@@ -122,6 +122,17 @@ module Omnibus
expect { build_version.semver }.to raise_error(ArgumentError)
end
it "uses ENV['BUILD_ID'] to generate timestamp if set and BUILD_TIMESTAMP is not set" do
stub_env("BUILD_ID", "2012-12-25_16-41-40")
expect(build_version.semver).to eq("11.0.0-alpha1+20121225164140.git.207.694b062")
end
it "fails on invalid ENV['BUILD_ID'] values" do
stub_env("BUILD_ID", "AAAA")
expect { build_version.semver }.to raise_error(ArgumentError)
end
context "prerelease version with dashes" do
let(:git_describe) { "11.0.0-alpha-3-207-g694b062" }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment