github_packages: fix more bulk upload errors.
- replace `+` in formula names (because it's an invalid character) - do a `skopeo inspect` first to avoid overwriting existing packages
This commit is contained in:
parent
6d0275ff57
commit
b0ba92466f
@ -163,7 +163,9 @@ 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, dry_run: args.dry_run?)
|
github_packages.upload_bottles(bottles_hash,
|
||||||
|
dry_run: args.dry_run?,
|
||||||
|
warn_on_error: args.warn_on_upload_failure?)
|
||||||
else
|
else
|
||||||
odie "Service specified by root_url is not recognized"
|
odie "Service specified by root_url is not recognized"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -44,8 +44,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], dry_run: T::Boolean).void }
|
sig { params(bottles_hash: T::Hash[String, T.untyped], dry_run: T::Boolean, warn_on_error: T::Boolean).void }
|
||||||
def upload_bottles(bottles_hash, dry_run:)
|
def upload_bottles(bottles_hash, dry_run:, warn_on_error:)
|
||||||
user = Homebrew::EnvConfig.github_packages_user
|
user = Homebrew::EnvConfig.github_packages_user
|
||||||
token = Homebrew::EnvConfig.github_packages_token
|
token = Homebrew::EnvConfig.github_packages_token
|
||||||
|
|
||||||
@ -71,7 +71,8 @@ class GitHubPackages
|
|||||||
load_schemas!
|
load_schemas!
|
||||||
|
|
||||||
bottles_hash.each do |formula_full_name, bottle_hash|
|
bottles_hash.each do |formula_full_name, bottle_hash|
|
||||||
upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run: dry_run)
|
upload_bottle(user, token, skopeo, formula_full_name, bottle_hash,
|
||||||
|
dry_run: dry_run, warn_on_error: warn_on_error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,7 +103,11 @@ class GitHubPackages
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.image_formula_name(formula_name)
|
def self.image_formula_name(formula_name)
|
||||||
|
# invalid docker name characters
|
||||||
|
# / makes sense because we already use it to separate repo/formula
|
||||||
|
# x makes sense because we already use it in Formulary
|
||||||
formula_name.tr("@", "/")
|
formula_name.tr("@", "/")
|
||||||
|
.tr("+", "x")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -168,7 +173,7 @@ class GitHubPackages
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run:)
|
def upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, dry_run:, warn_on_error:)
|
||||||
formula_name = bottle_hash["formula"]["name"]
|
formula_name = bottle_hash["formula"]["name"]
|
||||||
|
|
||||||
_, org, repo, = *bottle_hash["bottle"]["root_url"].match(URL_REGEX)
|
_, org, repo, = *bottle_hash["bottle"]["root_url"].match(URL_REGEX)
|
||||||
@ -177,6 +182,27 @@ class GitHubPackages
|
|||||||
version = bottle_hash["formula"]["pkg_version"]
|
version = bottle_hash["formula"]["pkg_version"]
|
||||||
rebuild = bottle_hash["bottle"]["rebuild"]
|
rebuild = bottle_hash["bottle"]["rebuild"]
|
||||||
version_rebuild = GitHubPackages.version_rebuild(version, rebuild)
|
version_rebuild = GitHubPackages.version_rebuild(version, rebuild)
|
||||||
|
|
||||||
|
image_formula_name = GitHubPackages.image_formula_name(formula_name)
|
||||||
|
image_tag = "#{GitHubPackages.root_url(org, repo, DOCKER_PREFIX)}/#{image_formula_name}:#{version_rebuild}"
|
||||||
|
|
||||||
|
puts
|
||||||
|
inspect_args = ["inspect", image_tag.to_s]
|
||||||
|
if dry_run
|
||||||
|
puts "#{skopeo} #{inspect_args.join(" ")} --dest-creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN"
|
||||||
|
else
|
||||||
|
inspect_args << "--dest-creds=#{user}:#{token}"
|
||||||
|
inspect_result = system_command(skopeo, args: args)
|
||||||
|
if inspect_result.status.success?
|
||||||
|
if warn_on_error
|
||||||
|
opoo "#{image_tag} already exists, skipping upload!"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
odie "#{image_tag} already exists!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
root = Pathname("#{formula_name}--#{version_rebuild}")
|
root = Pathname("#{formula_name}--#{version_rebuild}")
|
||||||
FileUtils.rm_rf root
|
FileUtils.rm_rf root
|
||||||
|
|
||||||
@ -316,9 +342,6 @@ class GitHubPackages
|
|||||||
write_index_json(index_json_sha256, index_json_size, root,
|
write_index_json(index_json_sha256, index_json_size, root,
|
||||||
"org.opencontainers.image.ref.name" => version_rebuild)
|
"org.opencontainers.image.ref.name" => version_rebuild)
|
||||||
|
|
||||||
image_formula_name = GitHubPackages.image_formula_name(formula_name)
|
|
||||||
image_tag = "#{GitHubPackages.root_url(org, repo, DOCKER_PREFIX)}/#{image_formula_name}:#{version_rebuild}"
|
|
||||||
|
|
||||||
puts
|
puts
|
||||||
args = ["copy", "--all", "oci:#{root}", image_tag.to_s]
|
args = ["copy", "--all", "oci:#{root}", image_tag.to_s]
|
||||||
if dry_run
|
if dry_run
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user