mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move artifact download code to separate file
This will help avoid mutually-recursive `require`s.
This commit is contained in:
parent
43b6d79a4c
commit
d7870bb24d
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
require "utils/github"
|
require "utils/github"
|
||||||
|
require "utils/github/artifacts"
|
||||||
require "tmpdir"
|
require "tmpdir"
|
||||||
require "formula"
|
require "formula"
|
||||||
|
|
||||||
|
@ -633,46 +633,6 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Strategy for downloading an artifact from GitHub Actions.
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
|
|
||||||
def initialize(url, artifact_id, token:)
|
|
||||||
super(url, "artifact", artifact_id)
|
|
||||||
@cache = HOMEBREW_CACHE/"gh-actions-artifact"
|
|
||||||
@token = token
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch(timeout: nil)
|
|
||||||
ohai "Downloading #{url}"
|
|
||||||
if cached_location.exist?
|
|
||||||
puts "Already downloaded: #{cached_location}"
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
curl "--location", "--create-dirs", "--output", temporary_path, url,
|
|
||||||
"--header", "Authorization: token #{@token}",
|
|
||||||
secrets: [@token],
|
|
||||||
timeout: timeout
|
|
||||||
rescue ErrorDuringExecution
|
|
||||||
raise CurlDownloadStrategyError, url
|
|
||||||
end
|
|
||||||
ignore_interrupts do
|
|
||||||
cached_location.dirname.mkpath
|
|
||||||
temporary_path.rename(cached_location)
|
|
||||||
symlink_location.dirname.mkpath
|
|
||||||
end
|
|
||||||
end
|
|
||||||
FileUtils.ln_s cached_location.relative_path_from(symlink_location.dirname), symlink_location, force: true
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
sig { returns(String) }
|
|
||||||
def resolved_basename
|
|
||||||
"artifact.zip"
|
|
||||||
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
|
||||||
|
@ -5,7 +5,6 @@ require "uri"
|
|||||||
require "utils/github/actions"
|
require "utils/github/actions"
|
||||||
require "utils/github/api"
|
require "utils/github/api"
|
||||||
|
|
||||||
require "download_strategy"
|
|
||||||
require "system_command"
|
require "system_command"
|
||||||
|
|
||||||
# Wrapper functions for the GitHub API.
|
# Wrapper functions for the GitHub API.
|
||||||
@ -372,26 +371,6 @@ module GitHub
|
|||||||
artifact.last["archive_download_url"]
|
artifact.last["archive_download_url"]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Downloads an artifact from GitHub Actions.
|
|
||||||
#
|
|
||||||
# @param url [String] URL to download from
|
|
||||||
# @param artifact_id [String] a value that uniquely identifies the downloaded artifact
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
sig { params(url: String, artifact_id: String).void }
|
|
||||||
def self.download_artifact(url, artifact_id)
|
|
||||||
odie "Credentials must be set to access the Artifacts API" if API.credentials_type == :none
|
|
||||||
|
|
||||||
token = API.credentials
|
|
||||||
|
|
||||||
# Download the artifact as a zip file and unpack it into `dir`. This is
|
|
||||||
# preferred over system `curl` and `tar` as this leverages the Homebrew
|
|
||||||
# cache to avoid repeated downloads of (possibly large) bottles.
|
|
||||||
downloader = GitHubArtifactDownloadStrategy.new(url, artifact_id, token: token)
|
|
||||||
downloader.fetch
|
|
||||||
downloader.stage
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.public_member_usernames(org, per_page: 100)
|
def self.public_member_usernames(org, per_page: 100)
|
||||||
url = "#{API_URL}/orgs/#{org}/public_members"
|
url = "#{API_URL}/orgs/#{org}/public_members"
|
||||||
members = []
|
members = []
|
||||||
|
67
Library/Homebrew/utils/github/artifacts.rb
Normal file
67
Library/Homebrew/utils/github/artifacts.rb
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# typed: true
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "download_strategy"
|
||||||
|
require "utils/github"
|
||||||
|
|
||||||
|
module GitHub
|
||||||
|
# Downloads an artifact from GitHub Actions.
|
||||||
|
#
|
||||||
|
# @param url [String] URL to download from
|
||||||
|
# @param artifact_id [String] a value that uniquely identifies the downloaded artifact
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
sig { params(url: String, artifact_id: String).void }
|
||||||
|
def self.download_artifact(url, artifact_id)
|
||||||
|
odie "Credentials must be set to access the Artifacts API" if API.credentials_type == :none
|
||||||
|
|
||||||
|
token = API.credentials
|
||||||
|
|
||||||
|
# Download the artifact as a zip file and unpack it into `dir`. This is
|
||||||
|
# preferred over system `curl` and `tar` as this leverages the Homebrew
|
||||||
|
# cache to avoid repeated downloads of (possibly large) bottles.
|
||||||
|
downloader = GitHubArtifactDownloadStrategy.new(url, artifact_id, token: token)
|
||||||
|
downloader.fetch
|
||||||
|
downloader.stage
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Strategy for downloading an artifact from GitHub Actions.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
|
||||||
|
def initialize(url, artifact_id, token:)
|
||||||
|
super(url, "artifact", artifact_id)
|
||||||
|
@cache = HOMEBREW_CACHE/"gh-actions-artifact"
|
||||||
|
@token = token
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch(timeout: nil)
|
||||||
|
ohai "Downloading #{url}"
|
||||||
|
if cached_location.exist?
|
||||||
|
puts "Already downloaded: #{cached_location}"
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
curl "--location", "--create-dirs", "--output", temporary_path, url,
|
||||||
|
"--header", "Authorization: token #{@token}",
|
||||||
|
secrets: [@token],
|
||||||
|
timeout: timeout
|
||||||
|
rescue ErrorDuringExecution
|
||||||
|
raise CurlDownloadStrategyError, url
|
||||||
|
end
|
||||||
|
ignore_interrupts do
|
||||||
|
cached_location.dirname.mkpath
|
||||||
|
temporary_path.rename(cached_location)
|
||||||
|
symlink_location.dirname.mkpath
|
||||||
|
end
|
||||||
|
end
|
||||||
|
FileUtils.ln_s cached_location.relative_path_from(symlink_location.dirname), symlink_location, force: true
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def resolved_basename
|
||||||
|
"artifact.zip"
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user