Class: GitHubPackages Private
- Inherits:
-
Object
- Object
- GitHubPackages
- Extended by:
- T::Sig
- Includes:
- Context
- Defined in:
- github_packages.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
GitHub Packages client.
Constant Summary collapse
- URL_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze
- TAB_ARCH_TO_PLATFORM_ARCHITECTURE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Translate Homebrew tab.arch to OCI platform.architecture
{ "arm64" => "arm64", "x86_64" => "amd64", }.freeze
- BUILT_ON_OS_TO_PLATFORM_OS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Translate Homebrew built_on.os to OCI platform.os
{ "Linux" => "linux", "Macintosh" => "darwin", }.freeze
Class Method Summary collapse
-
.image_formula_name(formula_name) ⇒ Object
private
-
.image_version_rebuild(version_rebuild) ⇒ Object
private
-
.repo_without_prefix(repo) ⇒ Object
private
-
.root_url(org, repo, prefix = URL_PREFIX) ⇒ Object
private
-
.root_url_if_match(url) ⇒ Object
private
-
.version_rebuild(version, rebuild, bottle_tag = nil) ⇒ Object
private
Instance Method Summary collapse
-
#initialize(org: "homebrew") ⇒ void
constructor
private
-
#inspect ⇒ String
private
-
#upload_bottles(bottles_hash, keep_old:, dry_run:, warn_on_error:) ⇒ void
private
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(org: "homebrew") ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
42 43 44 45 46 47 48 |
# File 'github_packages.rb', line 42 def initialize(org: "homebrew") @github_org = org raise UsageError, "Must set a GitHub organisation!" unless @github_org ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @github_org == "homebrew" && !OS.mac? end |
Class Method Details
.image_formula_name(formula_name) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
124 125 126 127 128 129 130 |
# File 'github_packages.rb', line 124 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("@", "/") .tr("+", "x") end |
.image_version_rebuild(version_rebuild) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
132 133 134 135 136 137 |
# File 'github_packages.rb', line 132 def self.image_version_rebuild(version_rebuild) # invalid docker tag characters # TODO: consider changing the actual versions here and make an audit to # avoid these weird characters being used version_rebuild.gsub(/[+#~]/, ".") end |
.repo_without_prefix(repo) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
103 104 105 106 |
# File 'github_packages.rb', line 103 def self.repo_without_prefix(repo) # remove redundant repo prefix for a shorter name repo.delete_prefix("homebrew-") end |
.root_url(org, repo, prefix = URL_PREFIX) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
108 109 110 111 112 113 |
# File 'github_packages.rb', line 108 def self.root_url(org, repo, prefix = URL_PREFIX) # docker/skopeo insist on lowercase org ("repository name") org = org.downcase "#{prefix}#{org}/#{repo_without_prefix(repo)}" end |
.root_url_if_match(url) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
115 116 117 118 119 120 121 122 |
# File 'github_packages.rb', line 115 def self.root_url_if_match(url) return if url.blank? _, org, repo, = *url.to_s.match(URL_REGEX) return if org.blank? || repo.blank? root_url(org, repo) end |
.version_rebuild(version, rebuild, bottle_tag = nil) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'github_packages.rb', line 89 def self.version_rebuild(version, rebuild, bottle_tag = nil) bottle_tag = (".#{bottle_tag}" if bottle_tag.present?) rebuild = if rebuild.to_i.positive? if bottle_tag ".#{rebuild}" else "-#{rebuild}" end end "#{version}#{bottle_tag}#{rebuild}" end |
Instance Method Details
#inspect ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
37 38 39 |
# File 'github_packages.rb', line 37 def inspect "#<GitHubPackages: org=#{@github_org}>" end |
#upload_bottles(bottles_hash, keep_old:, dry_run:, warn_on_error:) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'github_packages.rb', line 58 def upload_bottles(bottles_hash, keep_old:, dry_run:, warn_on_error:) user = Homebrew::EnvConfig.github_packages_user token = Homebrew::EnvConfig.github_packages_token raise UsageError, "HOMEBREW_GITHUB_PACKAGES_USER is unset." if user.blank? raise UsageError, "HOMEBREW_GITHUB_PACKAGES_TOKEN is unset." if token.blank? skopeo = [ which("skopeo"), which("skopeo", ENV["HOMEBREW_PATH"]), HOMEBREW_PREFIX/"bin/skopeo", ].compact.first unless skopeo.exist? 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" skopeo = Formula["skopeo"].opt_bin/"skopeo" end Homebrew.install_gem!("json_schemer") require "json_schemer" load_schemas! bottles_hash.each do |formula_full_name, bottle_hash| upload_bottle(user, token, skopeo, formula_full_name, bottle_hash, keep_old: keep_old, dry_run: dry_run, warn_on_error: warn_on_error) end end |