Skip to content

Commit 6b1d775

Browse files
authored
Merge pull request #21066 from Homebrew/github_actions_env_helper
Use GitHub Actions helper method more consistently.
2 parents 81e3411 + d82e129 commit 6b1d775

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

Library/Homebrew/dev-cmd/test-bot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TestBotCmd < AbstractCommand
120120

121121
sig { override.void }
122122
def run
123-
if ENV["GITHUB_ACTIONS"].present?
123+
if GitHub::Actions.env_set?
124124
ENV["HOMEBREW_COLOR"] = "1"
125125
ENV["HOMEBREW_GITHUB_ACTIONS"] = "1"
126126
end

Library/Homebrew/formula_auditor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def audit_homepage
545545

546546
# Skip gnu.org and nongnu.org audit on GitHub runners
547547
# See issue: https://github.com/Homebrew/homebrew-core/issues/206757
548-
github_runner = ENV.fetch("GITHUB_ACTIONS", nil) && !ENV["GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED"]
548+
github_runner = GitHub::Actions.env_set? && !ENV["GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED"]
549549
return if homepage.match?(%r{^https?://www\.(?:non)?gnu\.org/.+}) && github_runner
550550

551551
use_homebrew_curl = [:stable, :head].any? do |spec_name|

Library/Homebrew/test_bot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ module TestBot
2424
HOMEBREW_TAP_REGEX = %r{^([\w-]+)/homebrew-([\w-]+)$}
2525

2626
def cleanup?(args)
27-
args.cleanup? || ENV["GITHUB_ACTIONS"].present?
27+
args.cleanup? || GitHub::Actions.env_set?
2828
end
2929

3030
def local?(args)
31-
args.local? || ENV["GITHUB_ACTIONS"].present?
31+
args.local? || GitHub::Actions.env_set?
3232
end
3333

3434
def resolve_test_tap(tap = nil)

Library/Homebrew/test_bot/formulae.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run!(args:)
6868
puts
6969
end
7070

71-
return unless ENV["GITHUB_ACTIONS"]
71+
return unless GitHub::Actions.env_set?
7272

7373
# Remove `bash` after it is tested, since leaving a broken `bash`
7474
# installation in the environment can cause issues with subsequent
@@ -355,7 +355,7 @@ def livecheck(formula)
355355
"Error encountered (no message provided)"
356356
end
357357

358-
if ENV["GITHUB_ACTIONS"].present?
358+
if GitHub::Actions.env_set?
359359
puts GitHub::Actions::Annotation.new(
360360
:error,
361361
error_msg,
@@ -383,7 +383,7 @@ def livecheck(formula)
383383
"The formula version is newer than the version from `brew livecheck`."
384384
end
385385

386-
if ENV["GITHUB_ACTIONS"].present?
386+
if GitHub::Actions.env_set?
387387
puts GitHub::Actions::Annotation.new(
388388
:warning,
389389
newer_than_upstream_msg,
@@ -433,7 +433,7 @@ def formula!(formula_name, args:)
433433
build_flag = if build_bottle?(formula, args:)
434434
"--build-bottle"
435435
else
436-
if ENV["GITHUB_ACTIONS"].present?
436+
if GitHub::Actions.env_set?
437437
puts GitHub::Actions::Annotation.new(
438438
:warning,
439439
"#{formula} has unbottled dependencies, so a bottle will not be built.",

Library/Homebrew/test_bot/formulae_dependents.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def run!(args:)
4444
puts
4545
end
4646

47-
return unless ENV["GITHUB_ACTIONS"]
47+
return unless GitHub::Actions.env_set?
4848

4949
# Remove `bash` after it is tested, since leaving a broken `bash`
5050
# installation in the environment can cause issues with subsequent
@@ -360,7 +360,7 @@ def install_dependent(dependent, testable_dependents, args:, build_from_source:
360360
@tested_dependents_list.write("\n", mode: "a")
361361
end
362362

363-
return if ENV["GITHUB_ACTIONS"].blank?
363+
return unless GitHub::Actions.env_set?
364364

365365
if build_from_source &&
366366
!bottled_on_current_version &&

Library/Homebrew/test_bot/formulae_detect.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(argument, tap:, git:, dry_run:, fail_fast:, verbose:)
1818
def run!(args:)
1919
detect_formulae!(args:)
2020

21-
return unless ENV["GITHUB_ACTIONS"]
21+
return unless GitHub::Actions.env_set?
2222

2323
File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f|
2424
f.puts "testing_formulae=#{@testing_formulae.join(",")}"
@@ -60,7 +60,7 @@ def detect_formulae!(args:)
6060

6161
github_sha = ENV.fetch("GITHUB_SHA", nil)
6262
if github_repository.blank? || github_sha.blank? || github_ref.blank?
63-
if ENV["GITHUB_ACTIONS"]
63+
if GitHub::Actions.env_set?
6464
odie <<~EOS
6565
We cannot find the needed GitHub Actions environment variables! Check you have e.g. exported them to a Docker container.
6666
EOS

Library/Homebrew/test_bot/step.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "system_command"
5+
require "utils/github/actions"
56

67
module Homebrew
78
module TestBot
@@ -75,12 +76,8 @@ def puts_result
7576
puts Formatter.headline(Formatter.error("FAILED"), color: :red) unless passed?
7677
end
7778

78-
def in_github_actions?
79-
ENV["GITHUB_ACTIONS"].present?
80-
end
81-
8279
def puts_github_actions_annotation(message, title, file, line)
83-
return unless in_github_actions?
80+
return unless GitHub::Actions.env_set?
8481

8582
type = if passed?
8683
:notice
@@ -95,9 +92,9 @@ def puts_github_actions_annotation(message, title, file, line)
9592
end
9693

9794
def puts_in_github_actions_group(title)
98-
puts "::group::#{title}" if in_github_actions?
95+
puts "::group::#{title}" if GitHub::Actions.env_set?
9996
yield
100-
puts "::endgroup::" if in_github_actions?
97+
puts "::endgroup::" if GitHub::Actions.env_set?
10198
end
10299

103100
def output?
@@ -211,7 +208,7 @@ def run(dry_run: false, fail_fast: false)
211208

212209
puts_full_output
213210

214-
unless in_github_actions?
211+
unless GitHub::Actions.env_set?
215212
puts
216213
exit 1 if fail_fast && failed?
217214
return

Library/Homebrew/test_bot/test_formulae.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def github_event_payload
3434
def previous_github_sha
3535
return if tap.blank?
3636
return unless repository.directory?
37-
return if ENV["GITHUB_ACTIONS"].blank?
37+
return unless GitHub::Actions.env_set?
3838
return if (payload = github_event_payload).blank?
3939

4040
head_repo_owner = payload.dig("pull_request", "head", "repo", "owner", "login")
@@ -255,7 +255,7 @@ def install_formula_from_bottle!(formula_name, testing_formulae_dependents:, dry
255255
end
256256
bottle_message = "Bottle for #{formula_name} built at #{bottle_commit_details}".strip
257257

258-
if ENV["GITHUB_ACTIONS"].present?
258+
if GitHub::Actions.env_set?
259259
puts GitHub::Actions::Annotation.new(
260260
:notice,
261261
bottle_message,

0 commit comments

Comments
 (0)