Commit d96295c0 authored by Seth Chisamore's avatar Seth Chisamore

Merge pull request #568 from chef/schisamo/JEX-52-arbitrary-properties

[JEX-52] support custom properties in Artifactory publishing
parents 28fcce9b 84106717
......@@ -70,6 +70,10 @@ module Omnibus
type: :boolean,
desc: 'Optionally create an Artifactory build record for the published artifacts',
default: true
method_option :properties,
type: :hash,
desc: 'Properites to attach to published artifacts',
default: {}
desc 'artifactory REPOSITORY PATTERN', 'Publish to an Artifactory instance'
def artifactory(repository, pattern)
options[:repository] = repository
......
......@@ -38,10 +38,7 @@ module Omnibus
artifact_for(package).upload(
repository,
remote_path_for(package),
metadata_for(package).merge(
'build.name' => package.metadata[:name],
'build.number' => package.metadata[:version],
),
default_properties.merge(metadata_properties_for(package)),
)
end
rescue Artifactory::Error::HTTPError => e
......@@ -120,11 +117,11 @@ module Omnibus
name: 'omnibus',
version: Omnibus::VERSION,
},
properties: {
properties: default_properties.merge(
'omnibus.project' => name,
'omnibus.version' => manifest.build_version,
'omnibus.version_manifest' => manifest.to_json,
},
),
modules: [
{
# com.getchef:chef-server:12.0.0
......@@ -188,8 +185,8 @@ module Omnibus
#
# @return [Hash<String, String>]
#
def metadata_for(package)
{
def metadata_properties_for(package)
metadata = {
'omnibus.project' => package.metadata[:name],
'omnibus.platform' => package.metadata[:platform],
'omnibus.platform_version' => package.metadata[:platform_version],
......@@ -201,6 +198,20 @@ module Omnibus
'omnibus.sha256' => package.metadata[:sha256],
'omnibus.sha512' => package.metadata[:sha512],
}
metadata.merge!(
'build.name' => package.metadata[:name],
'build.number' => package.metadata[:version],
) if build_record?
metadata
end
#
# Properties to attach to published artifacts (and build record).
#
# @return [Hash<String, String>]
#
def default_properties
@properties ||= @options[:properties] || {}
end
#
......
......@@ -3,7 +3,6 @@ require 'spec_helper'
module Omnibus
describe ArtifactoryPublisher do
let(:path) { '/path/to/files/*.deb' }
let(:repository) { 'REPO' }
let(:package) do
......@@ -27,6 +26,8 @@ module Omnibus
platform_version: '14.04',
arch: 'x86_64',
sha1: 'SHA1',
sha256: 'SHA256',
sha512: 'SHA512',
md5: 'ABCDEF123456',
)
end
......@@ -36,6 +37,29 @@ module Omnibus
let(:artifact) { double('Artifactory::Resource::Artifact', upload: nil) }
let(:build) { double('Artifactory::Resource::Build') }
let(:transformed_metadata_values) do
{
"omnibus.architecture" => "x86_64",
"omnibus.iteration" => 1,
"omnibus.md5" => "ABCDEF123456",
"omnibus.platform" => "ubuntu",
"omnibus.platform_version" => "14.04",
"omnibus.project" => "chef",
"omnibus.sha1" => "SHA1",
"omnibus.sha256" => "SHA256",
"omnibus.sha512" => "SHA512",
"omnibus.version" => "11.0.6",
}
end
let(:build_values) do
{
"build.name" => "chef",
"build.number" => "11.0.6",
}
end
let(:options) { {repository: repository} }
before do
allow(subject).to receive(:client).and_return(client)
allow(subject).to receive(:artifact_for).and_return(artifact)
......@@ -44,7 +68,7 @@ module Omnibus
allow(build).to receive(:save)
end
subject { described_class.new(path, repository: repository) }
subject { described_class.new(path, options) }
describe '#publish' do
before do
......@@ -62,7 +86,7 @@ module Omnibus
expect(artifact).to receive(:upload).with(
repository,
'com/getchef/chef/11.0.6/ubuntu/14.04/chef.deb',
an_instance_of(Hash),
hash_including(transformed_metadata_values),
).once
subject.publish
......@@ -118,6 +142,51 @@ module Omnibus
subject.publish
end
end
context 'additional properties are provided' do
let(:delivery_props) do
{
'delivery.change' => '4dbf38de-3e82-439f-8090-c5f3e11aeba6',
'delivery.sha' => 'ec1cb62616350176fc6fd9b1dc4ad3153caa0791',
}
end
let(:options) do
{
properties: delivery_props,
repository: repository,
}
end
it 'uploads the package with the provided properties' do
expect(artifact).to receive(:upload).with(
repository,
'com/getchef/chef/11.0.6/ubuntu/14.04/chef.deb',
hash_including(transformed_metadata_values.merge(delivery_props)),
).once
subject.publish
end
end
end
describe '#metadata_properties_for' do
it 'returns the transformed package metadata values' do
expect(subject.send(:metadata_properties_for, package)).to include(transformed_metadata_values.merge(build_values))
end
context ':build_record is false' do
let(:options) do
{
build_record: false,
repository: repository,
}
end
it 'does not include `build.*` values' do
expect(subject.send(:metadata_properties_for, package)).to include(transformed_metadata_values)
expect(subject.send(:metadata_properties_for, package)).to_not include(build_values)
end
end
end
end
end
Markdown is supported
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