Skip to content

Commit

Permalink
Use architecture from platform mappings file
Browse files Browse the repository at this point in the history
This fixes the issue when in certain conditions packages
published erroneously because the matching logic wasn't
taking the architecture into account.

Signed-off-by: Jeremiah Snapp <[email protected]>
  • Loading branch information
jeremiahsnapp committed Aug 2, 2019
1 parent 0077920 commit 4306c04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
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

0 comments on commit 4306c04

Please sign in to comment.