Merge pull request #10938 from Homebrew/sj/pr-upload
pr-upload: Fix GitHub Packages for Linux and third-party taps
This commit is contained in:
commit
ab99855c12
@ -118,7 +118,7 @@ module Homebrew
|
|||||||
Upload bottles described by these JSON files to #{service}:
|
Upload bottles described by these JSON files to #{service}:
|
||||||
#{json_files.join("\n ")}
|
#{json_files.join("\n ")}
|
||||||
EOS
|
EOS
|
||||||
return
|
return unless github_packages?(bottles_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
check_bottled_formulae(bottles_hash)
|
check_bottled_formulae(bottles_hash)
|
||||||
@ -151,7 +151,7 @@ module Homebrew
|
|||||||
elsif github_packages?(bottles_hash)
|
elsif github_packages?(bottles_hash)
|
||||||
github_org = args.github_org || "homebrew"
|
github_org = args.github_org || "homebrew"
|
||||||
github_packages = GitHubPackages.new(org: github_org)
|
github_packages = GitHubPackages.new(org: github_org)
|
||||||
github_packages.upload_bottles(bottles_hash)
|
github_packages.upload_bottles(bottles_hash, dry_run: args.dry_run?)
|
||||||
else
|
else
|
||||||
odie "Service specified by root_url is not recognized"
|
odie "Service specified by root_url is not recognized"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,7 +14,8 @@ class GitHubPackages
|
|||||||
|
|
||||||
URL_DOMAIN = "ghcr.io"
|
URL_DOMAIN = "ghcr.io"
|
||||||
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
|
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
|
||||||
URL_REGEX = %r{#{Regexp.escape(URL_PREFIX)}([\w-]+)/([\w-]+)}.freeze
|
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/"
|
||||||
|
URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def inspect
|
def inspect
|
||||||
@ -30,8 +31,8 @@ class GitHubPackages
|
|||||||
ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @github_org == "homebrew" && !OS.mac?
|
ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @github_org == "homebrew" && !OS.mac?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(bottles_hash: T::Hash[String, T.untyped]).void }
|
sig { params(bottles_hash: T::Hash[String, T.untyped], dry_run: T::Boolean).void }
|
||||||
def upload_bottles(bottles_hash)
|
def upload_bottles(bottles_hash, dry_run:)
|
||||||
user = Homebrew::EnvConfig.github_packages_user
|
user = Homebrew::EnvConfig.github_packages_user
|
||||||
token = Homebrew::EnvConfig.github_packages_token
|
token = Homebrew::EnvConfig.github_packages_token
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class GitHubPackages
|
|||||||
load_schemas!
|
load_schemas!
|
||||||
|
|
||||||
bottles_hash.each_value do |bottle_hash|
|
bottles_hash.each_value do |bottle_hash|
|
||||||
upload_bottle(user, token, skopeo, bottle_hash)
|
upload_bottle(user, token, skopeo, bottle_hash, dry_run: dry_run)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ class GitHubPackages
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_bottle(user, token, skopeo, bottle_hash)
|
def upload_bottle(user, token, skopeo, bottle_hash, dry_run:)
|
||||||
formula_path = HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]
|
formula_path = HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]
|
||||||
formula = Formulary.factory(formula_path)
|
formula = Formulary.factory(formula_path)
|
||||||
formula_name = formula.name
|
formula_name = formula.name
|
||||||
@ -131,7 +132,7 @@ class GitHubPackages
|
|||||||
".#{rebuild}"
|
".#{rebuild}"
|
||||||
end
|
end
|
||||||
version_rebuild = "#{version}#{rebuild}"
|
version_rebuild = "#{version}#{rebuild}"
|
||||||
root = Pathname("#{formula_name}-#{version_rebuild}")
|
root = Pathname("#{formula_name}--#{version_rebuild}")
|
||||||
FileUtils.rm_rf root
|
FileUtils.rm_rf root
|
||||||
|
|
||||||
write_image_layout(root)
|
write_image_layout(root)
|
||||||
@ -144,13 +145,21 @@ class GitHubPackages
|
|||||||
git_revision = formula.tap.git_head
|
git_revision = formula.tap.git_head
|
||||||
git_path = formula_path.to_s.delete_prefix("#{formula.tap.path}/")
|
git_path = formula_path.to_s.delete_prefix("#{formula.tap.path}/")
|
||||||
source = "https://github.com/#{org}/#{repo}/blob/#{git_revision}/#{git_path}"
|
source = "https://github.com/#{org}/#{repo}/blob/#{git_revision}/#{git_path}"
|
||||||
|
documentation = if formula.tap.core_tap?
|
||||||
|
"https://formulae.brew.sh/formula/#{formula_name}"
|
||||||
|
else
|
||||||
|
formula.tap.remote
|
||||||
|
end
|
||||||
|
|
||||||
formula_annotations_hash = {
|
formula_annotations_hash = {
|
||||||
"org.opencontainers.image.created" => Time.now.strftime("%F"),
|
"org.opencontainers.image.created" => Time.now.strftime("%F"),
|
||||||
"org.opencontainers.image.description" => formula.desc,
|
"org.opencontainers.image.description" => formula.desc,
|
||||||
|
"org.opencontainers.image.documentation" => documentation,
|
||||||
"org.opencontainers.image.license" => formula.license,
|
"org.opencontainers.image.license" => formula.license,
|
||||||
|
"org.opencontainers.image.ref.name" => version_rebuild,
|
||||||
"org.opencontainers.image.revision" => git_revision,
|
"org.opencontainers.image.revision" => git_revision,
|
||||||
"org.opencontainers.image.source" => source,
|
"org.opencontainers.image.source" => source,
|
||||||
|
"org.opencontainers.image.title" => formula.full_name,
|
||||||
"org.opencontainers.image.url" => formula.homepage,
|
"org.opencontainers.image.url" => formula.homepage,
|
||||||
"org.opencontainers.image.vendor" => org,
|
"org.opencontainers.image.vendor" => org,
|
||||||
"org.opencontainers.image.version" => version,
|
"org.opencontainers.image.version" => version,
|
||||||
@ -159,6 +168,7 @@ class GitHubPackages
|
|||||||
formula_annotations_hash.delete(key) if value.blank?
|
formula_annotations_hash.delete(key) if value.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
created_times = []
|
||||||
manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash|
|
manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash|
|
||||||
local_file = tag_hash["local_filename"]
|
local_file = tag_hash["local_filename"]
|
||||||
odebug "Uploading #{local_file}"
|
odebug "Uploading #{local_file}"
|
||||||
@ -203,6 +213,7 @@ class GitHubPackages
|
|||||||
|
|
||||||
created_time = tab.source_modified_time
|
created_time = tab.source_modified_time
|
||||||
created_time ||= Time.now
|
created_time ||= Time.now
|
||||||
|
created_times << created_time
|
||||||
documentation = "https://formulae.brew.sh/#{formulae_dir}/#{formula_name}" if formula.tap.core_tap?
|
documentation = "https://formulae.brew.sh/#{formulae_dir}/#{formula_name}" if formula.tap.core_tap?
|
||||||
tag = "#{version}.#{bottle_tag}#{rebuild}"
|
tag = "#{version}.#{bottle_tag}#{rebuild}"
|
||||||
title = "#{formula.full_name} #{tag}"
|
title = "#{formula.full_name} #{tag}"
|
||||||
@ -258,12 +269,15 @@ class GitHubPackages
|
|||||||
package_name = "#{repo.delete_prefix("homebrew-")}/#{formula_name}"
|
package_name = "#{repo.delete_prefix("homebrew-")}/#{formula_name}"
|
||||||
image_tag = "#{org_prefix}/#{package_name}:#{version_rebuild}"
|
image_tag = "#{org_prefix}/#{package_name}:#{version_rebuild}"
|
||||||
puts
|
puts
|
||||||
system_command!(skopeo, verbose: true, print_stdout: true, args: [
|
args = ["copy", "--all", "oci:#{root}", image_tag.to_s]
|
||||||
"copy", "--dest-creds=#{user}:#{token}",
|
if dry_run
|
||||||
"oci:#{root}", "docker://#{image_tag}"
|
puts "#{skopeo} #{args.join(" ")} --dest-creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN"
|
||||||
])
|
else
|
||||||
|
args << "--dest-creds=#{user}:#{token}"
|
||||||
|
system_command!(skopeo, verbose: true, print_stdout: true, args: args)
|
||||||
ohai "Uploaded to https://github.com/orgs/Homebrew/packages/container/package/#{package_name}"
|
ohai "Uploaded to https://github.com/orgs/Homebrew/packages/container/package/#{package_name}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def write_image_layout(root)
|
def write_image_layout(root)
|
||||||
image_layout = { imageLayoutVersion: "1.0.0" }
|
image_layout = { imageLayoutVersion: "1.0.0" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user