From cdaeee03c4835991a91ac3eb372c26c63d915c39 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 5 Apr 2021 14:58:17 +0100 Subject: [PATCH] GitHub Packages cleanup - `download_strategy`: only request image index JSON for downloading the manifest for the tab - use a shared `OS` constant for the version of `glibc` we use in CI - fix `skoepeo` typo - ensure that blank hash values are deleted (again) rather than just `nil` ones - use a shared `Hardware::CPU` constant for oldest CPU we're supporting/using on Intel 64-bit - re-add comment to `software_spec` --- Library/Homebrew/download_strategy.rb | 3 ++- Library/Homebrew/formula_auditor.rb | 2 +- Library/Homebrew/github_packages.rb | 25 ++++++++++++++++++------- Library/Homebrew/hardware.rb | 4 +++- Library/Homebrew/os.rb | 2 ++ Library/Homebrew/software_spec.rb | 7 +++++-- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index b7e4cef109..59341f7706 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -563,7 +563,8 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy def initialize(url, name, version, **meta) meta ||= {} - meta[:header] = ["Authorization: Bearer", "Accept: application/vnd.oci.image.index.v1+json"] + meta[:headers] ||= [] + meta[:headers] << ["Authorization: Bearer"] super(url, name, version, meta) end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index d89819a5cb..8dc9bee4d9 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -343,7 +343,7 @@ module Homebrew return unless @core_tap version = formula.version.to_s - return if version == "2.23" + return if version == OS::GLIBC_CI_VERSION problem "The glibc version must be #{version}, as this is the version used by our CI on Linux. " \ "Glibc is for users who have a system Glibc with a lower version, " \ diff --git a/Library/Homebrew/github_packages.rb b/Library/Homebrew/github_packages.rb index c5def150f5..31ba0d1cf9 100644 --- a/Library/Homebrew/github_packages.rb +++ b/Library/Homebrew/github_packages.rb @@ -58,7 +58,7 @@ class GitHubPackages HOMEBREW_PREFIX/"bin/skopeo", ].compact.first unless skopeo.exist? - odie "no `skoepeo` and HOMEBREW_FORCE_HOMEBREW_ON_LINUX is set!" if Homebrew::EnvConfig.force_homebrew_on_linux? + odie "no `skopeo` and HOMEBREW_FORCE_HOMEBREW_ON_LINUX is set!" if Homebrew::EnvConfig.force_homebrew_on_linux? ohai "Installing `skopeo` for upload..." safe_system HOMEBREW_BREW_FILE, "install", "--formula", "skopeo" @@ -206,7 +206,8 @@ class GitHubPackages "org.opencontainers.image.url" => bottle_hash["formula"]["homepage"], "org.opencontainers.image.vendor" => org, "org.opencontainers.image.version" => version, - }.compact + } + delete_blank_hash_values(formula_annotations_hash) manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash| local_file = tag_hash["local_filename"] @@ -239,15 +240,17 @@ class GitHubPackages os_version ||= "macOS #{MacOS::Version.from_symbol(bottle_tag)}" when "linux" os_version = (os_version || "Ubuntu 16.04.7").delete_suffix " LTS" - glibc_version = (tab["built_on"]["glibc_version"] if tab["built_on"].present?) || "2.23" - cpu_variant = tab["oldest_cpu_family"] || "core2" + glibc_version = (tab["built_on"]["glibc_version"] if tab["built_on"].present?) || OS::GLIBC_CI_VERSION + cpu_variant = tab["oldest_cpu_family"] || Hardware::CPU::INTEL_64BIT_OLDEST_CPU.to_s end platform_hash = { architecture: architecture, os: os, "os.version" => os_version, - }.compact + } + delete_blank_hash_values(platform_hash) + tar_sha256 = Digest::SHA256.hexdigest( Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file), ) @@ -265,7 +268,8 @@ class GitHubPackages "sh.brew.bottle.digest" => tar_gz_sha256, "sh.brew.bottle.glibc.version" => glibc_version, "sh.brew.tab" => tab.to_json, - }.compact + } + delete_blank_hash_values(descriptor_annotations_hash) annotations_hash = formula_annotations_hash.merge(descriptor_annotations_hash).merge( { @@ -273,7 +277,8 @@ class GitHubPackages "org.opencontainers.image.documentation" => documentation, "org.opencontainers.image.title" => "#{formula_full_name} #{tag}", }, - ).compact.sort.to_h + ).sort.to_h + delete_blank_hash_values(annotations_hash) image_manifest = { schemaVersion: 2, @@ -381,4 +386,10 @@ class GitHubPackages [sha256, json.size] end + + def delete_blank_hash_values(hash) + hash.each do |key, value| + hash.delete(key) if value.blank? + end + end end diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 0cbcac435f..ee91222f51 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -20,6 +20,8 @@ module Hardware *ARM_64BIT_ARCHS, ].freeze + INTEL_64BIT_OLDEST_CPU = :core2 + class << self extend T::Sig @@ -198,7 +200,7 @@ module Hardware def oldest_cpu(_version = nil) if Hardware::CPU.intel? if Hardware::CPU.is_64_bit? - :core2 + Hardware::CPU::INTEL_64BIT_OLDEST_CPU else :core end diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index 7f0472ace9..0c55095eec 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -37,6 +37,8 @@ module OS ::OS_VERSION = ENV["HOMEBREW_OS_VERSION"] + GLIBC_CI_VERSION = "2.23" + if OS.mac? require "os/mac" # Don't tell people to report issues on unsupported configurations. diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index c3df3c1844..bbe3244373 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -306,6 +306,7 @@ class Bottle filename = Filename.create(formula, tag, spec.rebuild).bintray + # TODO: this will need adjusted when if we use GitHub Packages by default path, resolved_basename = if spec.root_url.match?(GitHubPackages::URL_REGEX) ["#{@name}/blobs/sha256:#{checksum}", filename] else @@ -400,8 +401,10 @@ class Bottle version_rebuild = GitHubPackages.version_rebuild(@resource.version, rebuild) resource.version(version_rebuild) - resource.url("#{@spec.root_url}/#{name}/manifests/#{version_rebuild}", - using: CurlGitHubPackagesDownloadStrategy) + resource.url("#{@spec.root_url}/#{name}/manifests/#{version_rebuild}", { + using: CurlGitHubPackagesDownloadStrategy, + headers: ["Accept: application/vnd.oci.image.index.v1+json"], + }) resource.downloader.resolved_basename = "#{name}-#{version_rebuild}.bottle_manifest.json" resource end