Refactor GitHub artifact downloads out of dev-cmd/pr-pull
I plan to use these in `test-bot` to download built bottles from previous CI runs.
This commit is contained in:
parent
f7b3225574
commit
05337cbb79
@ -1,7 +1,6 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "download_strategy"
|
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
require "utils/github"
|
require "utils/github"
|
||||||
require "tmpdir"
|
require "tmpdir"
|
||||||
@ -356,28 +355,6 @@ module Homebrew
|
|||||||
formulae + casks
|
formulae + casks
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.download_artifact(url, dir, pull_request)
|
|
||||||
odie "Credentials must be set to access the Artifacts API" if GitHub::API.credentials_type == :none
|
|
||||||
|
|
||||||
token = GitHub::API.credentials
|
|
||||||
curl_args = ["--header", "Authorization: token #{token}"]
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
FileUtils.chdir dir do
|
|
||||||
downloader = GitHubArtifactDownloadStrategy.new(
|
|
||||||
url,
|
|
||||||
"artifact",
|
|
||||||
pull_request,
|
|
||||||
curl_args: curl_args,
|
|
||||||
secrets: [token],
|
|
||||||
)
|
|
||||||
downloader.fetch
|
|
||||||
downloader.stage
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.pr_check_conflicts(repo, pull_request)
|
def self.pr_check_conflicts(repo, pull_request)
|
||||||
long_build_pr_files = GitHub.issues(
|
long_build_pr_files = GitHub.issues(
|
||||||
repo: repo, state: "open", labels: "no long build conflict",
|
repo: repo, state: "open", labels: "no long build conflict",
|
||||||
@ -505,7 +482,7 @@ module Homebrew
|
|||||||
|
|
||||||
ohai "Downloading bottles for workflow: #{workflow}"
|
ohai "Downloading bottles for workflow: #{workflow}"
|
||||||
url = GitHub.get_artifact_url(workflow_run)
|
url = GitHub.get_artifact_url(workflow_run)
|
||||||
download_artifact(url, dir, pr)
|
GitHub.download_artifact(url, pr, dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
next if args.no_upload?
|
next if args.no_upload?
|
||||||
@ -526,34 +503,3 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
|
|
||||||
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,
|
|
||||||
*meta.fetch(:curl_args, []),
|
|
||||||
secrets: meta.fetch(:secrets, []),
|
|
||||||
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
|
|
||||||
|
|||||||
@ -633,6 +633,40 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Strategy for downloading an artifact from GitHub Actions.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
|
||||||
|
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,
|
||||||
|
*meta.fetch(:curl_args, []),
|
||||||
|
secrets: meta.fetch(:secrets, []),
|
||||||
|
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,6 +5,7 @@ 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.
|
||||||
@ -371,6 +372,28 @@ module GitHub
|
|||||||
artifact.last["archive_download_url"]
|
artifact.last["archive_download_url"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.download_artifact(url, artifact_id, dir = Pathname.pwd)
|
||||||
|
odie "Credentials must be set to access the Artifacts API" if API.credentials_type == :none
|
||||||
|
|
||||||
|
token = API.credentials
|
||||||
|
curl_args = ["--header", "Authorization: token #{token}"]
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
FileUtils.chdir dir do
|
||||||
|
downloader = GitHubArtifactDownloadStrategy.new(
|
||||||
|
url,
|
||||||
|
"artifact",
|
||||||
|
artifact_id,
|
||||||
|
curl_args: curl_args,
|
||||||
|
secrets: [token],
|
||||||
|
)
|
||||||
|
downloader.fetch
|
||||||
|
downloader.stage
|
||||||
|
end
|
||||||
|
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 = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user