Class: GitHubPackages Private

Inherits:
Object
  • Object
show all
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_DOMAIN =

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.

"ghcr.io"
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

Instance Method Summary collapse

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.

Parameters:

  • org (String, nil) (defaults to: "homebrew")

Raises:



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.



121
122
123
124
125
126
127
# File 'github_packages.rb', line 121

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.



129
130
131
132
133
134
# File 'github_packages.rb', line 129

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.



100
101
102
103
# File 'github_packages.rb', line 100

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.



105
106
107
108
109
110
# File 'github_packages.rb', line 105

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.



112
113
114
115
116
117
118
119
# File 'github_packages.rb', line 112

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.



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'github_packages.rb', line 86

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

#inspectString

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.

Returns:



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.

Parameters:

  • bottles_hash (Hash{String => T.untyped})
  • keep_old (Boolean)
  • dry_run (Boolean)
  • warn_on_error (Boolean)

Raises:



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
# 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?
    ohai "Installing `skopeo` for upload..."
    safe_system HOMEBREW_BREW_FILE, "install", "--formula", "skopeo"
    skopeo = Formula["skopeo"].opt_bin/"skopeo"
  end

  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