Module: Fastlane::AppstorePrecheck::Runner

Defined in:
lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb

Constant Summary collapse

VERDICTS =
%w[GREEN YELLOW RED].freeze
FAIL_ON_LEVELS =
%w[RED YELLOW].freeze

Class Method Summary collapse

Class Method Details

.gate_hit?(verdict, fail_on) ⇒ Boolean

True when the verdict is at or past the gate level.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb', line 36

def gate_hit?(verdict, fail_on)
  return false unless VERDICTS.include?(verdict.to_s)

  if fail_on.to_s.upcase == 'YELLOW'
    verdict != 'GREEN'
  else
    verdict == 'RED'
  end
end

.parse_verdict(output) ⇒ Object

Extract the verdict from scanner output; nil if absent.



30
31
32
33
# File 'lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb', line 30

def parse_verdict(output)
  match = output.to_s.match(/^VERDICT:\s*(GREEN|YELLOW|RED)/)
  match && match[1]
end

.resolve_command(cli_path: nil, which: ->(bin) { system_which(bin) }) ⇒ Object

Resolve the scanner command as an argv array, or nil if none is available. Preference order: explicit cli_path, appstore-precheck on PATH (brew / npm -g), then npx --yes appstore-precheck.



14
15
16
17
18
19
20
# File 'lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb', line 14

def resolve_command(cli_path: nil, which: ->(bin) { system_which(bin) })
  return [cli_path] if cli_path && !cli_path.to_s.empty?
  return ['appstore-precheck'] if which.call('appstore-precheck')
  return ['npx', '--yes', 'appstore-precheck'] if which.call('npx')

  nil
end

.system_which(bin) ⇒ Object



22
23
24
25
26
27
# File 'lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb', line 22

def system_which(bin)
  ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).any? do |dir|
    candidate = File.join(dir, bin)
    File.executable?(candidate) && !File.directory?(candidate)
  end
end

.valid_fail_on?(level) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fastlane/plugin/appstore_precheck/helper/appstore_precheck_runner.rb', line 46

def valid_fail_on?(level)
  FAIL_ON_LEVELS.include?(level.to_s.upcase)
end