From 503f6dc0490fa9c25dabf574229496d755fa0077 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sun, 11 Apr 2021 04:35:24 +0100 Subject: [PATCH] github_packages: safer handling of `skopeo inspect` --- Library/Homebrew/github_packages.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/github_packages.rb b/Library/Homebrew/github_packages.rb index ca7d8dc3fe..bb485cbe95 100644 --- a/Library/Homebrew/github_packages.rb +++ b/Library/Homebrew/github_packages.rb @@ -227,16 +227,28 @@ class GitHubPackages image_uri = "#{GitHubPackages.root_url(org, repo, DOCKER_PREFIX)}/#{image_name}:#{image_tag}" puts - inspect_args = ["inspect", image_uri.to_s] + inspect_args = ["inspect", "--raw", image_uri.to_s] if dry_run puts "#{skopeo} #{inspect_args.join(" ")} --creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN" else inspect_args << "--creds=#{user}:#{token}" inspect_result = system_command(skopeo, print_stderr: false, args: inspect_args) - if keep_old - # Tag doesn't exist so ignore --keep-old + + # Order here is important + if !inspect_result.status.success? && inspect_result.stderr.exclude?("name unknown") + # We got an error, and it was not about the tag or package being unknown. + if warn_on_error + opoo "#{image_uri} inspection returned an error, skipping upload!\n#{inspect_result.stderr}" + return + else + odie "#{image_uri} inspection returned an error!\n#{inspect_result.stderr}" + end + elsif keep_old + # If the tag doesn't exist, ignore --keep-old. keep_old = false unless inspect_result.status.success? + # Otherwise, do nothing - the tag already existing is expected behaviour for --keep-old. elsif inspect_result.status.success? + # The tag already exists, and we are not passing --keep-old. if warn_on_error opoo "#{image_uri} already exists, skipping upload!" return