Class: GitHubArtifactDownloadStrategy Private

Inherits:
AbstractFileDownloadStrategy show all
Defined in:
utils/github/artifacts.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.

Strategy for downloading an artifact from GitHub Actions.

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #url

Instance Method Summary collapse

Methods inherited from AbstractFileDownloadStrategy

#basename, #cached_location, #symlink_location, #temporary_path

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #quiet!, #quiet?, #source_modified_time, #stage

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(url, artifact_id, token:) ⇒ 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:



28
29
30
31
32
# File 'utils/github/artifacts.rb', line 28

def initialize(url, artifact_id, token:)
  super(url, "artifact", artifact_id)
  @cache = T.let(HOMEBREW_CACHE/"gh-actions-artifact", Pathname)
  @token = T.let(token, String)
end

Instance Method Details

#fetch(timeout: nil) ⇒ 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:

  • timeout (Integer, nil) (defaults to: nil)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'utils/github/artifacts.rb', line 35

def fetch(timeout: nil)
  ohai "Downloading #{url}"
  if cached_location.exist?
    puts "Already downloaded: #{cached_location}"
  else
    begin
      Utils::Curl.curl("--location", "--create-dirs", "--output", temporary_path, url,
                       "--header", "Authorization: token #{@token}",
                       secrets: [@token],
                       timeout:)
    rescue ErrorDuringExecution
      raise CurlDownloadStrategyError, url
    end
    cached_location.dirname.mkpath
    temporary_path.rename(cached_location)
  end

  symlink_location.dirname.mkpath
  FileUtils.ln_s cached_location.relative_path_from(symlink_location.dirname), symlink_location, force: true
end