Module: Fastlane::Helper::FirebaseAppDistributionHelper

Instance Method Summary collapse

Instance Method Details

#app_id_from_params(params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 40

def app_id_from_params(params)
  plist_path = params[:googleservice_info_plist_path]
  if params[:app]
    UI.message("Using app ID from 'app' parameter")
    app_id = params[:app]
  elsif xcode_archive_path
    UI.message("Using app ID from the GoogleService-Info.plist file located using the 'googleservice_info_plist_path' parameter, relative to the archive path: #{xcode_archive_path}")
    app_id = get_ios_app_id_from_archive_plist(xcode_archive_path, plist_path)
  elsif plist_path
    UI.message("Using app ID from the GoogleService-Info.plist file located using the 'googleservice_info_plist_path' parameter directly since no archive path was found")
    app_id = get_ios_app_id_from_plist(plist_path)
  end
  if app_id.nil?
    UI.crash!(ErrorMessage::MISSING_APP_ID)
  end
  app_id
end

#app_name_from_app_id(app_id) ⇒ Object



102
103
104
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 102

def app_name_from_app_id(app_id)
  "#{project_name(project_number_from_app_id(app_id))}/apps/#{app_id}"
end

#binary_type_from_path(binary_path) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 12

def binary_type_from_path(binary_path)
  extension = File.extname(binary_path)
  return :APK if extension == '.apk'
  return :AAB if extension == '.aab'
  return :IPA if extension == '.ipa'

  UI.user_error!("Unsupported distribution file format, should be .ipa, .apk or .aab")
end

#blank?(value) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 89

def blank?(value)
  # Taken from https://apidock.com/rails/Object/blank%3F
  value.respond_to?(:empty?) ? value.empty? : !value
end

#deep_symbolize_keys(hash) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 127

def deep_symbolize_keys(hash)
  result = {}
  hash.each do |key, value|
    result[key.to_sym] = value.kind_of?(Hash) ? deep_symbolize_keys(value) : value
  end
  result
end

#get_ios_app_id_from_archive_plist(archive_path, relative_plist_path) ⇒ Object



77
78
79
80
81
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 77

def get_ios_app_id_from_archive_plist(archive_path, relative_plist_path)
  app_path = parse_plist("#{archive_path}/Info.plist")["ApplicationProperties"]["ApplicationPath"]
  UI.shell_error!("can't extract application path from Info.plist at #{archive_path}") if app_path.empty?
  return get_ios_app_id_from_plist("#{archive_path}/Products/#{app_path}/#{relative_plist_path}")
end

#get_ios_app_id_from_plist(plist_path) ⇒ Object



83
84
85
86
87
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 83

def get_ios_app_id_from_plist(plist_path)
  identifier = parse_plist(plist_path)["GOOGLE_APP_ID"]
  UI.shell_error!("can't extract GOOGLE_APP_ID from #{plist_path}") if identifier.empty?
  return identifier
end

#get_value_from_value_or_file(value, path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 21

def get_value_from_value_or_file(value, path)
  if (value.nil? || value.empty?) && !path.nil?
    begin
      return File.open(path).read
    rescue Errno::ENOENT
      UI.crash!("#{ErrorMessage::INVALID_PATH}: #{path}")
    end
  end
  value
end

#group_name(project_number, group_alias) ⇒ Object



110
111
112
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 110

def group_name(project_number, group_alias)
  "#{project_name(project_number)}/groups/#{group_alias}"
end

#init_google_api_client(debug, timeout = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 114

def init_google_api_client(debug, timeout = nil)
  if debug
    UI.important("Warning: Debug logging enabled. Output may include sensitive information.")
    Google::Apis.logger.level = Logger::DEBUG
  end

  Google::Apis::ClientOptions.default.application_name = "fastlane"
  Google::Apis::ClientOptions.default.application_version = Fastlane::FirebaseAppDistribution::VERSION
  unless timeout.nil?
    Google::Apis::ClientOptions.default.send_timeout_sec = timeout
  end
end

#lane_platformObject



58
59
60
61
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 58

def lane_platform
  # to_sym shouldn't be necessary, but possibly fixes #376
  Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]&.to_sym
end

#parse_plist(path) ⇒ Object



73
74
75
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 73

def parse_plist(path)
  CFPropertyList.native_types(CFPropertyList::List.new(file: path).value)
end

#present?(value) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 94

def present?(value)
  !blank?(value)
end

#project_name(project_number) ⇒ Object



106
107
108
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 106

def project_name(project_number)
  "projects/#{project_number}"
end

#project_number_from_app_id(app_id) ⇒ Object



98
99
100
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 98

def project_number_from_app_id(app_id)
  app_id.split(':')[1]
end

#string_to_array(string, delimiter = /[,\n]/) ⇒ Object

Returns the array representation of a string with trimmed comma seperated values.



34
35
36
37
38
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 34

def string_to_array(string, delimiter = /[,\n]/)
  return [] if string.nil?
  # Strip string and then strip individual values
  string.strip.split(delimiter).map(&:strip)
end

#xcode_archive_pathObject



63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_helper.rb', line 63

def xcode_archive_path
  # prevents issues on cross-platform build environments where an XCode build happens within
  # the same lane
  return nil if lane_platform == :android

  # rubocop:disable Require/MissingRequireStatement
  Actions.lane_context[Actions::SharedValues::XCODEBUILD_ARCHIVE]
  # rubocop:enable Require/MissingRequireStatement
end