Module: Homebrew::TestBot Private

Includes:
Kernel
Defined in:
test_bot.rb,
test_bot/step.rb,
test_bot/test.rb,
test_bot/junit.rb,
test_bot/setup.rb,
test_bot/formulae.rb,
test_bot/tap_syntax.rb,
test_bot/test_runner.rb,
test_bot/test_cleanup.rb,
test_bot/bottles_fetch.rb,
test_bot/cleanup_after.rb,
test_bot/test_formulae.rb,
test_bot/cleanup_before.rb,
test_bot/formulae_detect.rb,
test_bot/formulae_dependents.rb,
test_bot.rbi,
test_bot/test_runner.rbi,
test_bot/test_formulae.rbi

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Defined Under Namespace

Modules: TestRunner Classes: BottlesFetch, CleanupAfter, CleanupBefore, Formulae, FormulaeDependents, FormulaeDetect, Junit, Setup, Step, TapSyntax, Test, TestCleanup, TestFormulae

Constant Summary collapse

GIT =

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.

"/usr/bin/git"
HOMEBREW_TAP_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{^([\w-]+)/homebrew-([\w-]+)$}

Constants included from Kernel

Kernel::IGNORE_INTERRUPTS_MUTEX

Class Method Summary collapse

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #quiet_system, #redact_secrets, #redirect_stdout, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

Class Method Details

.cleanup?(args) ⇒ Boolean

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:

  • (Boolean)


26
27
28
# File 'test_bot.rb', line 26

def cleanup?(args)
  args.cleanup? || ENV["GITHUB_ACTIONS"].present?
end

.local?(args) ⇒ Boolean

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:

  • (Boolean)


30
31
32
# File 'test_bot.rb', line 30

def local?(args)
  args.local? || ENV["GITHUB_ACTIONS"].present?
end

.resolve_test_tap(tap = 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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'test_bot.rb', line 34

def resolve_test_tap(tap = nil)
  return Tap.fetch(tap) if tap

  # Get tap from GitHub Actions GITHUB_REPOSITORY
  git_url = ENV.fetch("GITHUB_REPOSITORY", nil)
  return if git_url.blank?

  url_path = git_url.sub(%r{^https?://github\.com/}, "")
                    .chomp("/")
                    .sub(/\.git$/, "")

  return CoreTap.instance if url_path == CoreTap.instance.full_name

  begin
    Tap.fetch(url_path) if url_path.match?(HOMEBREW_TAP_REGEX)
  rescue
    # Don't care if tap fetch fails
    nil
  end
end

.run!(args) ⇒ 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.



55
56
57
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'test_bot.rb', line 55

def run!(args)
  $stdout.sync = true
  $stderr.sync = true

  if Pathname.pwd == HOMEBREW_PREFIX && cleanup?(args)
    raise UsageError, "cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output."
  end

  ENV["HOMEBREW_DOWNLOAD_CONCURRENCY"] = "auto" if args.concurrent_downloads?
  ENV["HOMEBREW_DEVELOPER"] = "1"
  ENV["HOMEBREW_NO_AUTO_UPDATE"] = "1"
  ENV["HOMEBREW_NO_EMOJI"] = "1"
  ENV["HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK"] = "1"
  ENV["HOMEBREW_FAIL_LOG_LINES"] = "150"
  ENV["HOMEBREW_CURL"] = ENV["HOMEBREW_CURL_PATH"] = "/usr/bin/curl"
  ENV["HOMEBREW_GIT"] = ENV["HOMEBREW_GIT_PATH"] = GIT
  ENV["HOMEBREW_DISALLOW_LIBNSL1"] = "1"
  ENV["HOMEBREW_NO_ENV_HINTS"] = "1"
  ENV["HOMEBREW_PATH"] = ENV["PATH"] =
    "#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:#{ENV.fetch("PATH")}"

  if local?(args)
    home = "#{Dir.pwd}/home"
    logs = "#{Dir.pwd}/logs"
    gitconfig = "#{Dir.home}/.gitconfig"
    ENV["HOMEBREW_HOME"] = ENV["HOME"] = home
    ENV["HOMEBREW_LOGS"] = logs
    FileUtils.mkdir_p home
    FileUtils.mkdir_p logs
    FileUtils.cp gitconfig, home if File.exist?(gitconfig)
  end

  tap = resolve_test_tap(args.tap)

  if tap&.core_tap?
    ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
    ENV["HOMEBREW_VERIFY_ATTESTATIONS"] = "1" if args.only_formulae?
  end

  # Tap repository if required, this is done before everything else
  # because Formula parsing and/or git commit hash lookup depends on it.
  # At the same time, make sure Tap is not a shallow clone.
  # bottle rebuild and bottle upload rely on full clone.
  if tap
    if !tap.path.exist?
      safe_system "brew", "tap", tap.name
    elsif (tap.path/".git/shallow").exist?
      raise unless quiet_system GIT, "-C", tap.path, "fetch", "--unshallow"
    end
  end

  brew_version = Utils.safe_popen_read(
    GIT, "-C", HOMEBREW_REPOSITORY.to_s,
    "describe", "--tags", "--abbrev", "--dirty"
  ).strip
  brew_commit_subject = Utils.safe_popen_read(
    GIT, "-C", HOMEBREW_REPOSITORY.to_s,
    "log", "-1", "--format=%s"
  ).strip
  puts Formatter.headline("Using Homebrew/brew #{brew_version} (#{brew_commit_subject})", color: :cyan)

  if tap.to_s != CoreTap.instance.name && CoreTap.instance.installed?
    core_revision = Utils.safe_popen_read(
      GIT, "-C", CoreTap.instance.path.to_s,
      "log", "-1", "--format=%h (%s)"
    ).strip
    puts Formatter.headline("Using #{CoreTap.instance.full_name} #{core_revision}", color: :cyan)
  end

  if tap
    tap_github = " (#{ENV["GITHUB_REPOSITORY"]}" if tap.full_name != ENV["GITHUB_REPOSITORY"]
    tap_revision = Utils.safe_popen_read(
      GIT, "-C", tap.path.to_s,
      "log", "-1", "--format=%h (%s)"
    ).strip
    puts Formatter.headline("Testing #{tap.full_name}#{tap_github} #{tap_revision}:", color: :cyan)
  end

  ENV["HOMEBREW_GIT_NAME"] = args.git_name || "BrewTestBot"
  ENV["HOMEBREW_GIT_EMAIL"] = args.git_email ||
                              "1589480+BrewTestBot@users.noreply.github.com"

  Homebrew.failed = !TestRunner.run!(tap, git: GIT, args:)
end