Support downloading bottles from GitHub Packages
This commit is contained in:
parent
8e646f6202
commit
1d32dc9067
@ -13,6 +13,8 @@ require "mechanize/http/content_disposition_parser"
|
|||||||
|
|
||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
|
|
||||||
|
require "github_packages"
|
||||||
|
|
||||||
# @abstract Abstract superclass for all download strategies.
|
# @abstract Abstract superclass for all download strategies.
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
@ -527,6 +529,25 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Strategy for downloading a file from an GitHub Packages URL.
|
||||||
|
#
|
||||||
|
# @api public
|
||||||
|
class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
|
||||||
|
attr_accessor :checksum, :name
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _fetch(url:, resolved_url:)
|
||||||
|
raise "Empty checksum" if checksum.blank?
|
||||||
|
raise "Empty name" if name.blank?
|
||||||
|
|
||||||
|
_, org, repo, = *url.match(GitHubPackages::URL_REGEX)
|
||||||
|
|
||||||
|
blob_url = "https://ghcr.io/v2/#{org}/#{repo}/#{name}/blobs/sha256:#{checksum}"
|
||||||
|
curl_download(blob_url, "--header", "Authorization: Bearer", to: temporary_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Strategy for downloading a file from an Apache Mirror URL.
|
# Strategy for downloading a file from an Apache Mirror URL.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
@ -1243,6 +1264,8 @@ class DownloadStrategyDetector
|
|||||||
|
|
||||||
def self.detect_from_url(url)
|
def self.detect_from_url(url)
|
||||||
case url
|
case url
|
||||||
|
when GitHubPackages::URL_REGEX
|
||||||
|
CurlGitHubPackagesDownloadStrategy
|
||||||
when %r{^https?://github\.com/[^/]+/[^/]+\.git$}
|
when %r{^https?://github\.com/[^/]+/[^/]+\.git$}
|
||||||
GitHubGitDownloadStrategy
|
GitHubGitDownloadStrategy
|
||||||
when %r{^https?://.+\.git$},
|
when %r{^https?://.+\.git$},
|
||||||
|
|||||||
@ -316,12 +316,16 @@ class Bottle
|
|||||||
|
|
||||||
def fetch(verify_download_integrity: true)
|
def fetch(verify_download_integrity: true)
|
||||||
# add the default bottle domain as a fallback mirror
|
# add the default bottle domain as a fallback mirror
|
||||||
|
# TODO: this may need adjusted when if we use GitHub Packages by default
|
||||||
if @resource.download_strategy == CurlDownloadStrategy &&
|
if @resource.download_strategy == CurlDownloadStrategy &&
|
||||||
@resource.url.start_with?(Homebrew::EnvConfig.bottle_domain)
|
@resource.url.start_with?(Homebrew::EnvConfig.bottle_domain)
|
||||||
fallback_url = @resource.url
|
fallback_url = @resource.url
|
||||||
.sub(/^#{Regexp.escape(Homebrew::EnvConfig.bottle_domain)}/,
|
.sub(/^#{Regexp.escape(Homebrew::EnvConfig.bottle_domain)}/,
|
||||||
HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
|
HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
|
||||||
@resource.mirror(fallback_url) if [@resource.url, *@resource.mirrors].exclude?(fallback_url)
|
@resource.mirror(fallback_url) if [@resource.url, *@resource.mirrors].exclude?(fallback_url)
|
||||||
|
elsif @resource.download_strategy == CurlGitHubPackagesDownloadStrategy
|
||||||
|
@resource.downloader.name = @name
|
||||||
|
@resource.downloader.checksum = @resource.checksum.hexdigest
|
||||||
end
|
end
|
||||||
@resource.fetch(verify_download_integrity: verify_download_integrity)
|
@resource.fetch(verify_download_integrity: verify_download_integrity)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user