Module: FastlaneCore::Helper

Defined in:
lib/fastlane_core/helper.rb

Class Method Summary collapse

Class Method Details

.ci?boolean

Returns true if building in a known CI environment.

Returns:

  • (boolean)

    true if building in a known CI environment



52
53
54
55
56
57
58
# File 'lib/fastlane_core/helper.rb', line 52

def self.ci?
  # Check for Jenkins, Travis CI, ... environment variables
  ['JENKINS_URL', 'TRAVIS', 'CIRCLECI', 'CI'].each do |current|
    return true if ENV.key?(current)
  end
  return false
end

.fastlane_enabled?Boolean

Returns:

  • (Boolean)


118
119
120
121
# File 'lib/fastlane_core/helper.rb', line 118

def self.fastlane_enabled?
  # This is called from the root context on the first start
  @@enabled ||= File.directory? "./fastlane"
end

.gem_path(gem_name) ⇒ Object

Path to the installed gem to load resources (e.g. resign.sh)



124
125
126
127
128
129
130
# File 'lib/fastlane_core/helper.rb', line 124

def self.gem_path(gem_name)
  if !Helper.is_test? and Gem::Specification.find_all_by_name(gem_name).any?
    return Gem::Specification.find_by_name(gem_name).gem_dir
  else
    return './'
  end
end

.is_ci?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fastlane_core/helper.rb', line 71

def self.is_ci?
  ci?
end

.is_mac?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/fastlane_core/helper.rb', line 75

def self.is_mac?
  self.mac?
end

.is_test?Boolean

Use Helper.test? and Helper.ci? instead (legacy calls) rubocop:disable Style/PredicateName

Returns:

  • (Boolean)


67
68
69
# File 'lib/fastlane_core/helper.rb', line 67

def self.is_test?
  self.test?
end

.logObject

Logging happens using this method



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fastlane_core/helper.rb', line 6

def self.log
  if is_test?
    @@log ||= Logger.new(nil) # don't show any logs when running tests
  else
    @@log ||= Logger.new($stdout)
  end

  @@log.formatter = proc do |severity, datetime, progname, msg|
    string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: " if $verbose
    string = "[#{datetime.strftime('%H:%M:%S')}]: " unless $verbose
    second = "#{msg}\n"

    if severity == "DEBUG"
      string = string.magenta
    elsif severity == "INFO"
      string = string.white
    elsif severity == "WARN"
      string = string.yellow
    elsif severity == "ERROR"
      string = string.red
    elsif severity == "FATAL"
      string = string.red.bold
    end

    [string, second].join("")
  end

  @@log
end

.log_alert(text) ⇒ Object

This method can be used to add nice lines around the actual log Use this to log more important things The logs will be green automatically



39
40
41
42
43
44
# File 'lib/fastlane_core/helper.rb', line 39

def self.log_alert(text)
  i = text.length + 8
  Helper.log.info(("-" * i).green)
  Helper.log.info("--- ".green + text.green + " ---".green)
  Helper.log.info(("-" * i).green)
end

.mac?Boolean

Is the currently running computer a Mac?

Returns:

  • (Boolean)


61
62
63
# File 'lib/fastlane_core/helper.rb', line 61

def self.mac?
  (/darwin/ =~ RUBY_PLATFORM) != nil
end

.test?Boolean

Returns true if the currently running program is a unit test.

Returns:

  • (Boolean)

    true if the currently running program is a unit test



47
48
49
# File 'lib/fastlane_core/helper.rb', line 47

def self.test?
  defined?SpecHelper
end

.transporter_pathObject

Returns the full path to the iTMSTransporter executable.

Returns:

  • the full path to the iTMSTransporter executable



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fastlane_core/helper.rb', line 105

def self.transporter_path
  return '' unless self.is_mac? # so tests work on Linx too

  [
    "../Applications/Application Loader.app/Contents/MacOS/itms/bin/iTMSTransporter",
    "../Applications/Application Loader.app/Contents/itms/bin/iTMSTransporter"
  ].each do |path|
    result = File.join(self.xcode_path, path)
    return result if File.exist?(result)
  end
  raise "Could not find transporter at #{self.xcode_path}. Please make sure you set the correct path to your Xcode installation.".red
end

.xcode_pathObject

Returns the full path to the Xcode developer tools of the currently running system.

Returns:

  • the full path to the Xcode developer tools of the currently running system



85
86
87
88
# File 'lib/fastlane_core/helper.rb', line 85

def self.xcode_path
  return "" if self.is_test? and !self.is_mac?
  `xcode-select -p`.delete("\n") + "/"
end

.xcode_versionObject

Returns The version of the currently used Xcode installation (e.g. “7.0”).

Returns:

  • The version of the currently used Xcode installation (e.g. “7.0”)



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fastlane_core/helper.rb', line 91

def self.xcode_version
  return @xcode_version if @xcode_version

  begin
    output = `DEVELOPER_DIR='' "#{xcode_path}/usr/bin/xcodebuild" -version`
    @xcode_version = output.split("\n").first.split(' ')[1]
  rescue => ex
    Helper.log.error ex
    Helper.log.error "Error detecting currently used Xcode installation".red
  end
  @xcode_version
end