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

Use architecture from platform mappings file when publishing packages #896

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions features/step_definitions/generator_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
Given(/^I have a platform mappings file named "(.+)"$/) do |name|
write_file(name, <<-EOH.gsub(/^ {4}/, ""))
{
"ubuntu-10.04": [
"ubuntu-10.04",
"ubuntu-12.04",
"ubuntu-14.04"
"ubuntu-10.04-x86_64": [
"ubuntu-10.04-x86_64",
"ubuntu-12.04-x86_64",
"ubuntu-14.04-x86_64"
]
}
EOH
Expand Down
10 changes: 5 additions & 5 deletions lib/omnibus/cli/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class Command::Publish < Command::Base
#
# @example JSON
# {
# "ubuntu-10.04": [
# "ubuntu-10.04",
# "ubuntu-12.04",
# "ubuntu-14.04"
# "ubuntu-10.04-x86_64": [
# "ubuntu-10.04-x86_64",
# "ubuntu-12.04-x86_64",
# "ubuntu-14.04-x86_64"
# ]
# }
#
Expand Down Expand Up @@ -99,7 +99,7 @@ def publish(klass, pattern, options)
end

klass.publish(pattern, options) do |package|
say("Published '#{package.name}' for #{package.metadata[:platform]}-#{package.metadata[:platform_version]}", :green)
say("Published '#{package.name}' for #{package.metadata[:platform]}-#{package.metadata[:platform_version]}-#{package.metadata[:arch]}", :green)
end
end
end
Expand Down
22 changes: 12 additions & 10 deletions lib/omnibus/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def publish(pattern, options = {}, &block)
# mapping of build to publish platform(s)
# @example
# {
# 'ubuntu-10.04' => [
# 'ubuntu-10.04',
# 'ubuntu-12.04',
# 'ubuntu-14.04',
# 'ubuntu-10.04-x86_64' => [
# 'ubuntu-10.04-x86_64',
# 'ubuntu-12.04-x86_64',
# 'ubuntu-14.04-x86_64',
# ],
# }
#
Expand Down Expand Up @@ -75,33 +75,35 @@ def packages
if @options[:platform_mappings]
# the platform map is a simple hash with publish to build platform mappings
@options[:platform_mappings].each_pair do |build_platform, publish_platforms|
# Splits `ubuntu-12.04` into `ubuntu` and `12.04`
build_platform, build_platform_version = build_platform.rpartition("-") - %w{ - }
# Splits `ubuntu-12.04-x86_64` into `ubuntu`, `12.04` and `x86_64`
build_platform, build_platform_version, build_architecture = build_platform.split("-")

# locate the package for the build platform
packages = build_packages.select do |p|
p.metadata[:platform] == build_platform &&
p.metadata[:platform_version] == build_platform_version
p.metadata[:platform_version] == build_platform_version &&
p.metadata[:arch] == build_architecture
end

if packages.empty?
log.warn(log_key) do
"Could not locate a package for build platform #{build_platform}-#{build_platform_version}. " \
"Could not locate a package for build platform #{build_platform}-#{build_platform_version}-#{build_architecture}. " \
"Publishing will be skipped for: #{publish_platforms.join(', ')}"
end
end

publish_platforms.each do |publish_platform|
publish_platform, publish_platform_version = publish_platform.rpartition("-") - %w{ - }
publish_platform, publish_platform_version, publish_architecture = publish_platform.split("-")

packages.each do |p|
# create a copy of our package before mucking with its metadata
publish_package = p.dup
publish_metadata = p.metadata.dup.to_hash

# override the platform and platform version in the metadata
# override the platform, platform version and architecture in the metadata
publish_metadata[:platform] = publish_platform
publish_metadata[:platform_version] = publish_platform_version
publish_metadata[:arch] = publish_architecture

# Set the updated metadata on the package object
publish_package.metadata = Metadata.new(publish_package, publish_metadata)
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class FakePublisher; end
let(:options) do
{
platform_mappings: {
"ubuntu-12.04" => [
"ubuntu-12.04",
"ubuntu-14.04",
"ubuntu-12.04-x86_64" => [
"ubuntu-12.04-x86_64",
"ubuntu-14.04-x86_64",
],
},
}
Expand Down Expand Up @@ -155,17 +155,17 @@ class FakePublisher; end
let(:options) do
{
platform_mappings: {
"ubuntu-10.04" => [
"ubuntu-12.04",
"ubuntu-14.04",
"ubuntu-10.04-x86_64" => [
"ubuntu-12.04-x86_64",
"ubuntu-14.04-x86_64",
],
},
}
end

it "prints a warning" do
output = capture_logging { subject.packages }
expect(output).to include("Could not locate a package for build platform ubuntu-10.04. Publishing will be skipped for: ubuntu-12.04, ubuntu-14.04")
expect(output).to include("Could not locate a package for build platform ubuntu-10.04-x86_64. Publishing will be skipped for: ubuntu-12.04-x86_64, ubuntu-14.04-x86_64")
end
end
end
Expand Down