Class: Fastlane::Actions::FirebaseAppDistributionAction

Inherits:
Action
  • Object
show all
Extended by:
Fastlane::Auth::FirebaseAppDistributionAuthClient, Helper::FirebaseAppDistributionHelper
Defined in:
lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb

Constant Summary

Constants included from Fastlane::Auth::FirebaseAppDistributionAuthClient

Fastlane::Auth::FirebaseAppDistributionAuthClient::REDACTION_CHARACTER, Fastlane::Auth::FirebaseAppDistributionAuthClient::REDACTION_EXPOSED_LENGTH, Fastlane::Auth::FirebaseAppDistributionAuthClient::TOKEN_CREDENTIAL_URI

Class Method Summary collapse

Methods included from Fastlane::Auth::FirebaseAppDistributionAuthClient

fetch_auth_token

Methods included from Helper::FirebaseAppDistributionHelper

app_name_from_app_id, binary_type_from_path, blank?, get_ios_app_id_from_archive_plist, get_value_from_value_or_file, parse_plist, present?, string_to_array

Class Method Details

.app_id_from_params(params) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 83

def self.app_id_from_params(params)
  if params[:app]
    app_id = params[:app]
  elsif xcode_archive_path
    plist_path = params[:googleservice_info_plist_path]
    app_id = get_ios_app_id_from_archive_plist(xcode_archive_path, plist_path)
  end
  if app_id.nil?
    UI.crash!(ErrorMessage::MISSING_APP_ID)
  end
  app_id
end

.authorsObject



74
75
76
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 74

def self.authors
  ["Stefan Natchev", "Manny Jimenez Github: mannyjimenez0810, Alonso Salas Infante Github: alonsosalasinfante"]
end

.available_optionsObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 161

def self.available_options
  [
    # iOS Specific
    FastlaneCore::ConfigItem.new(key: :ipa_path,
                                 env_name: "FIREBASEAPPDISTRO_IPA_PATH",
                                 description: "Path to your IPA file. Optional if you use the _gym_ or _xcodebuild_ action",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :googleservice_info_plist_path,
                                 env_name: "GOOGLESERVICE_INFO_PLIST_PATH",
                                 description: "Path to your GoogleService-Info.plist file, relative to the archived product path",
                                 default_value: "GoogleService-Info.plist",
                                 optional: true,
                                 type: String),
    # Android Specific
    FastlaneCore::ConfigItem.new(key: :apk_path,
                                 env_name: "FIREBASEAPPDISTRO_APK_PATH",
                                 description: "Path to your APK file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :android_artifact_path,
                                 env_name: "FIREBASEAPPDISTRO_ANDROID_ARTIFACT_PATH",
                                 description: "Path to your APK or AAB file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :android_artifact_type,
                                 env_name: "FIREBASEAPPDISTRO_ANDROID_ARTIFACT_TYPE",
                                 description: "Android artifact type. Set to 'APK' or 'AAB'. Defaults to 'APK' if not set",
                                 default_value: "APK",
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("firebase_app_distribution: '#{value}' is not a valid value for android_artifact_type. Should be 'APK' or 'AAB'") unless ['APK', 'AAB'].include?(value)
                                 end),
    # Generic
    FastlaneCore::ConfigItem.new(key: :app,
                                 env_name: "FIREBASEAPPDISTRO_APP",
                                 description: "Your app's Firebase App ID. You can find the App ID in the Firebase console, on the General Settings page",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :firebase_cli_path,
                                 deprecated: "This plugin no longer uses the Firebase CLI",
                                 env_name: "FIREBASEAPPDISTRO_FIREBASE_CLI_PATH",
                                 description: "The absolute path of the firebase cli command",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :groups,
                                 env_name: "FIREBASEAPPDISTRO_GROUPS",
                                 description: "The group aliases used for distribution, separated by commas",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :groups_file,
                                 env_name: "FIREBASEAPPDISTRO_GROUPS_FILE",
                                 description: "The group aliases used for distribution, separated by commas",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :testers,
                                 env_name: "FIREBASEAPPDISTRO_TESTERS",
                                 description: "Pass email addresses of testers, separated by commas",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :testers_file,
                                 env_name: "FIREBASEAPPDISTRO_TESTERS_FILE",
                                 description: "Pass email addresses of testers, separated by commas",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :release_notes,
                                 env_name: "FIREBASEAPPDISTRO_RELEASE_NOTES",
                                 description: "Release notes for this build",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :release_notes_file,
                                 env_name: "FIREBASEAPPDISTRO_RELEASE_NOTES_FILE",
                                 description: "Release notes file for this build",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :firebase_cli_token,
                                 description: "Auth token generated using 'fastlane run firebase_app_distribution_login', or the Firebase CLI's login:ci command",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :debug,
                                 description: "Print verbose debug output",
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :service_credentials_file,
                                 description: "Path to Google service account json",
                                 optional: true,
                                 type: String)
  ]
end

.descriptionObject



70
71
72
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 70

def self.description
  "Release your beta builds with Firebase App Distribution"
end

.detailsObject

supports markdown.



79
80
81
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 79

def self.details
  "Release your beta builds with Firebase App Distribution"
end

.example_codeObject



257
258
259
260
261
262
263
264
265
266
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 257

def self.example_code
  [
    <<-CODE
      firebase_app_distribution(
        app: "<your Firebase app ID>",
        testers: "[email protected], [email protected]"
      )
    CODE
  ]
end

.get_binary_path(platform, params) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 116

def self.get_binary_path(platform, params)
  if platform == :ios
    return params[:ipa_path] ||
           Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] ||
           Dir["*.ipa"].sort_by { |x| File.mtime(x) }.last
  end

  if platform == :android
    return params[:apk_path] || params[:android_artifact_path] if params[:apk_path] || params[:android_artifact_path]

    if params[:android_artifact_type] == 'AAB'
      return Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH] ||
             Dir["*.aab"].last ||
             Dir[File.join("app", "build", "outputs", "bundle", "release", "app-release.aab")].last
    end

    return Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] ||
           Dir["*.apk"].last ||
           Dir[File.join("app", "build", "outputs", "apk", "release", "app-release.apk")].last
  end
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


249
250
251
252
253
254
255
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 249

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.lane_platformObject



104
105
106
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 104

def self.lane_platform
  Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
end

.platform_from_app_id(app_id) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 108

def self.platform_from_app_id(app_id)
  if app_id.include?(':ios:')
    :ios
  elsif app_id.include?(':android:')
    :android
  end
end

.release_notes(params) ⇒ Object



155
156
157
158
159
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 155

def self.release_notes(params)
  release_notes_param =
    get_value_from_value_or_file(params[:release_notes], params[:release_notes_file])
  release_notes_param || Actions.lane_context[SharedValues::FL_CHANGELOG]
end

.run(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 18

def self.run(params)
  params.values # to validate all inputs before looking for the ipa/apk/aab

  if params[:debug]
    UI.important("Warning: Debug logging enabled. Output may include sensitive information.")
  end

  app_id = app_id_from_params(params)
  app_name = app_name_from_app_id(app_id)
  platform = lane_platform || platform_from_app_id(app_id)

  binary_path = get_binary_path(platform, params)
  UI.user_error!("Couldn't find binary") if binary_path.nil?
  UI.user_error!("Couldn't find binary at path #{binary_path}") unless File.exist?(binary_path)
  binary_type = binary_type_from_path(binary_path)

  auth_token = fetch_auth_token(
    params[:service_credentials_file], params[:firebase_cli_token], params[:debug]
  )
  fad_api_client = Client::FirebaseAppDistributionApiClient.new(auth_token, params[:debug])

  # If binary is an AAB, get the AAB info for this app, which includes the integration state and certificate data
  if binary_type == :AAB
    aab_info = fad_api_client.get_aab_info(app_name)
    validate_aab_setup!(aab_info)
  end

  release_name = fad_api_client.upload(app_name, binary_path, platform.to_s)

  if binary_type == :AAB && aab_info && !aab_info.certs_provided?
    updated_aab_info = fad_api_client.get_aab_info(app_name)
    if updated_aab_info.certs_provided?
      UI.message("After you upload an AAB for the first time, App Distribution " \
        "generates a new test certificate. All AAB uploads are re-signed with this test " \
        "certificate. Use the certificate fingerprints below to register your app " \
        "signing key with API providers, such as Google Sign-In and Google Maps.\n" \
        "MD-1 certificate fingerprint: #{updated_aab_info.md5_certificate_hash}\n" \
        "SHA-1 certificate fingerprint: #{updated_aab_info.sha1_certificate_hash}\n" \
        "SHA-256 certificate fingerprint: #{updated_aab_info.sha256_certificate_hash}")
    end
  end

  fad_api_client.update_release_notes(release_name, release_notes(params))

  testers = get_value_from_value_or_file(params[:testers], params[:testers_file])
  groups = get_value_from_value_or_file(params[:groups], params[:groups_file])
  emails = string_to_array(testers)
  group_aliases = string_to_array(groups)
  fad_api_client.distribute(release_name, emails, group_aliases)
  UI.success("🎉 App Distribution upload finished successfully.")
end

.validate_aab_setup!(aab_info) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 138

def self.validate_aab_setup!(aab_info)
  if aab_info && aab_info.integration_state != AabInfo::AabState::INTEGRATED && aab_info.integration_state != AabInfo::AabState::UNAVAILABLE
    case aab_info.integration_state
    when AabInfo::AabState::PLAY_ACCOUNT_NOT_LINKED
      UI.user_error!(ErrorMessage::PLAY_ACCOUNT_NOT_LINKED)
    when AabInfo::AabState::APP_NOT_PUBLISHED
      UI.user_error!(ErrorMessage::APP_NOT_PUBLISHED)
    when AabInfo::AabState::NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT
      UI.user_error!(ErrorMessage::NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT)
    when AabInfo::AabState::PLAY_IAS_TERMS_NOT_ACCEPTED
      UI.user_error!(ErrorMessage::PLAY_IAS_TERMS_NOT_ACCEPTED)
    else
      UI.user_error!(ErrorMessage.aab_upload_error(aab_info.integration_state))
    end
  end
end

.xcode_archive_pathObject



96
97
98
99
100
101
102
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb', line 96

def self.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

  Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE]
end