Skip to content

Commit fc0d7b9

Browse files
authored
Miscellaneous cleanup. (#350)
- consistently end messages with period (except in cases where a sentence ends with a colon followed by a value - sleep before polling for upload status (because the server needs some time for asynchronous processing after upload) - reorder/refactor some code
1 parent 7033753 commit fc0d7b9

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class FirebaseAppDistributionAction < Action
2020
extend Helper::FirebaseAppDistributionHelper
2121

2222
DEFAULT_UPLOAD_TIMEOUT_SECONDS = 300
23-
MAX_POLLING_RETRIES = 60
24-
POLLING_INTERVAL_SECONDS = 5
23+
UPLOAD_MAX_POLLING_RETRIES = 60
24+
UPLOAD_POLLING_INTERVAL_SECONDS = 5
2525

2626
def self.run(params)
2727
params.values # to validate all inputs before looking for the ipa/apk/aab
@@ -32,15 +32,16 @@ def self.run(params)
3232
timeout = get_upload_timeout(params)
3333

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

3939
# TODO(lkellogg): This sets the send timeout for all POST requests made by the client, but
4040
# ideally the timeout should only apply to the binary upload
4141
init_google_api_client(params[:debug], timeout)
42+
authorization = get_authorization(params[:service_credentials_file], params[:firebase_cli_token], params[:debug])
4243
client = Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService.new
43-
client.authorization = get_authorization(params[:service_credentials_file], params[:firebase_cli_token], params[:debug])
44+
client.authorization = authorization
4445

4546
# If binary is an AAB, get the AAB info for this app, which includes the integration state
4647
# and certificate data
@@ -50,9 +51,9 @@ def self.run(params)
5051
end
5152

5253
binary_type = binary_type_from_path(binary_path)
53-
UI.message(" Uploading the #{binary_type}.")
54+
UI.message("📡 Uploading the #{binary_type}.")
5455
operation = upload_binary(app_name, binary_path, client, timeout)
55-
UI.message("🕵️ Validating upload.")
56+
UI.message("🕵️ Validating upload")
5657
release = poll_upload_release_operation(client, operation, binary_type)
5758

5859
if binary_type == :AAB && aab_info && !aab_certs_included?(aab_info.test_certificate)
@@ -214,24 +215,22 @@ def self.release_notes(params)
214215
end
215216

216217
def self.poll_upload_release_operation(client, operation, binary_type)
217-
operation = client.get_project_app_release_operation(operation.name)
218-
MAX_POLLING_RETRIES.times do
218+
UPLOAD_MAX_POLLING_RETRIES.times do
219+
sleep(UPLOAD_POLLING_INTERVAL_SECONDS)
220+
operation = client.get_project_app_release_operation(operation.name)
219221
if operation.done && operation.response && operation.response['release']
220222
release = extract_release(operation)
221-
result = operation.response['result']
222-
if result == 'RELEASE_UPDATED'
223+
case operation.response['result']
224+
when 'RELEASE_UPDATED'
223225
UI.success("✅ Uploaded #{binary_type} successfully; updated provisioning profile of existing release #{release_version(release)}.")
224-
break
225-
elsif result == 'RELEASE_UNMODIFIED'
226+
when 'RELEASE_UNMODIFIED'
226227
UI.success("✅ The same #{binary_type} was found in release #{release_version(release)} with no changes, skipping.")
227-
break
228228
else
229229
UI.success("✅ Uploaded #{binary_type} successfully and created release #{release_version(release)}.")
230230
end
231231
break
232232
elsif !operation.done
233-
sleep(POLLING_INTERVAL_SECONDS)
234-
operation = client.get_project_app_release_operation(operation.name)
233+
next
235234
else
236235
if operation.error && operation.error.message
237236
UI.user_error!("#{ErrorMessage.upload_binary_error(binary_type)}: #{operation.error.message}")
@@ -350,7 +349,7 @@ def self.available_options
350349
verify_block: proc do |value|
351350
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)
352351
end),
353-
# Generic
352+
# General
354353
FastlaneCore::ConfigItem.new(key: :app,
355354
env_name: "FIREBASEAPPDISTRO_APP",
356355
description: "Your app's Firebase App ID. You can find the App ID in the Firebase console, on the General Settings page",
@@ -361,6 +360,18 @@ def self.available_options
361360
env_name: "FIREBASEAPPDISTRO_FIREBASE_CLI_PATH",
362361
description: "The absolute path of the firebase cli command",
363362
type: String),
363+
FastlaneCore::ConfigItem.new(key: :debug,
364+
description: "Print verbose debug output",
365+
optional: true,
366+
default_value: false,
367+
type: Boolean),
368+
369+
# Release Distribution
370+
FastlaneCore::ConfigItem.new(key: :upload_timeout,
371+
description: "The amount of seconds before the upload will timeout, if not completed",
372+
optional: true,
373+
default_value: DEFAULT_UPLOAD_TIMEOUT_SECONDS,
374+
type: Integer),
364375
FastlaneCore::ConfigItem.new(key: :groups,
365376
env_name: "FIREBASEAPPDISTRO_GROUPS",
366377
description: "The group aliases used for distribution, separated by commas",
@@ -391,24 +402,16 @@ def self.available_options
391402
description: "Release notes file for this build",
392403
optional: true,
393404
type: String),
405+
406+
# Auth
394407
FastlaneCore::ConfigItem.new(key: :firebase_cli_token,
395408
description: "Auth token generated using the Firebase CLI's login:ci command",
396409
optional: true,
397410
type: String),
398-
FastlaneCore::ConfigItem.new(key: :debug,
399-
description: "Print verbose debug output",
400-
optional: true,
401-
default_value: false,
402-
is_string: false),
403411
FastlaneCore::ConfigItem.new(key: :service_credentials_file,
404412
description: "Path to Google service account json",
405413
optional: true,
406-
type: String),
407-
FastlaneCore::ConfigItem.new(key: :upload_timeout,
408-
description: "The amount of seconds before the upload will timeout, if not completed",
409-
optional: true,
410-
default_value: DEFAULT_UPLOAD_TIMEOUT_SECONDS,
411-
type: Integer)
414+
type: String)
412415
]
413416
end
414417

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
module ErrorMessage
22
MISSING_CREDENTIALS = "Missing authentication credentials. Set up Application Default Credentials, your Firebase refresh token, or sign in with the Firebase CLI, and try again."
3-
MISSING_APP_ID = "Missing app id. Please check that the app parameter is set and try again"
4-
SERVICE_CREDENTIALS_NOT_FOUND = "Service credentials file does not exist. Please check the service credentials path and try again"
5-
PARSE_SERVICE_CREDENTIALS_ERROR = "Failed to extract service account information from the service credentials file"
6-
PARSE_FIREBASE_TOOLS_JSON_ERROR = "Encountered error parsing json file. Ensure the firebase-tools.json file is formatted correctly"
7-
UPLOAD_RELEASE_NOTES_ERROR = "App Distribution halted because it had a problem uploading release notes"
8-
UPLOAD_TESTERS_ERROR = "App Distribution halted because it had a problem adding testers/groups"
9-
GET_RELEASE_TIMEOUT = "App Distribution failed to fetch release information"
3+
MISSING_APP_ID = "Missing app id. Please check that the app parameter is set and try again."
4+
SERVICE_CREDENTIALS_NOT_FOUND = "Service credentials file does not exist. Please check the service credentials path and try again."
5+
PARSE_SERVICE_CREDENTIALS_ERROR = "Failed to extract service account information from the service credentials file."
6+
PARSE_FIREBASE_TOOLS_JSON_ERROR = "Encountered error parsing json file. Ensure the firebase-tools.json file is formatted correctly."
7+
UPLOAD_RELEASE_NOTES_ERROR = "App Distribution halted because it had a problem uploading release notes."
8+
UPLOAD_TESTERS_ERROR = "App Distribution halted because it had a problem adding testers/groups."
9+
GET_RELEASE_TIMEOUT = "App Distribution failed to fetch release information."
1010
REFRESH_TOKEN_ERROR = "App Distribution could not generate credentials from the refresh token specified."
11-
APP_NOT_ONBOARDED_ERROR = "App Distribution not onboarded"
11+
APP_NOT_ONBOARDED_ERROR = "App Distribution not onboarded."
1212
INVALID_APP_ID = "App Distribution could not find your app. Make sure to onboard your app by pressing the \"Get started\" button on the App Distribution page in the Firebase console: https://console.firebase.google.com/project/_/appdistribution. App ID"
1313
INVALID_PROJECT = "App Distribution could not find your Firebase project. Make sure to onboard an app in your project by pressing the \"Get started\" button on the App Distribution page in the Firebase console: https://console.firebase.google.com/project/_/appdistribution."
1414
INVALID_PATH = "Could not read content from"
1515
INVALID_TESTERS = "Could not enable access for testers. Check that the tester emails are formatted correctly, the groups exist and you are using group aliases (not group names) for specifying groups."
1616
INVALID_TESTER_GROUP = "App Distribution could not find your tester group. Make sure that it exists before trying to add testers, and that the group alias is specified correctly."
1717
INVALID_TESTER_GROUP_NAME = "The tester group name should be 4-63 characters, and valid characters are /[a-z][0-9]-/."
18-
INVALID_RELEASE_NOTES = "Failed to set release notes"
19-
SERVICE_CREDENTIALS_ERROR = "App Distribution could not generate credentials from the service credentials file specified"
18+
INVALID_RELEASE_NOTES = "Failed to set release notes."
19+
SERVICE_CREDENTIALS_ERROR = "App Distribution could not generate credentials from the service credentials file specified."
2020
PLAY_ACCOUNT_NOT_LINKED = "This project is not linked to a Google Play account."
2121
APP_NOT_PUBLISHED = "This app is not published in the Google Play console."
2222
NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT = "App with matching package name does not exist in Google Play."
2323
PLAY_IAS_TERMS_NOT_ACCEPTED = "You must accept the Play Internal App Sharing (IAS) terms to upload AABs."
2424
INVALID_EMAIL_ADDRESS = "You passed an invalid email address."
25-
TESTER_LIMIT_VIOLATION = "Creating testers would exceed tester limit"
25+
TESTER_LIMIT_VIOLATION = "Creating testers would exceed tester limit."
2626

2727
def self.aab_upload_error(aab_state)
2828
"Failed to process the AAB: #{aab_state}"
2929
end
3030

3131
def self.binary_not_found(binary_type)
32-
"Could not find the #{binary_type}. Make sure you set the #{binary_type} path parameter to point to your #{binary_type}"
32+
"Could not find the #{binary_type}. Make sure you set the #{binary_type} path parameter to point to your #{binary_type}."
3333
end
3434

3535
def self.parse_binary_metadata_error(binary_type)
36-
"Failed to extract #{binary_type} metadata from the #{binary_type} path"
36+
"Failed to extract #{binary_type} metadata from the #{binary_type} path."
3737
end
3838

3939
def self.upload_binary_error(binary_type)
40-
"App Distribution halted because it had a problem uploading the #{binary_type}"
40+
"App Distribution halted because it had a problem uploading the #{binary_type}."
4141
end
4242

4343
def self.binary_processing_error(binary_type)
44-
"App Distribution failed to process the #{binary_type}"
44+
"App Distribution failed to process the #{binary_type}."
4545
end
4646
end

spec/firebase_app_distribution_action_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@
228228
it 'raises error if it cannot find a valid binary path' do
229229
expect do
230230
action.run(params.merge(ipa_path: nil))
231-
end.to raise_error("Couldn't find binary")
231+
end.to raise_error("Couldn't find binary.")
232232
end
233233

234234
it 'raises error if binary does not exist' do
235235
expect do
236236
action.run(params)
237-
end.to raise_error("Couldn't find binary at path debug.ipa")
237+
end.to raise_error("Couldn't find binary at path debug.ipa.")
238238
end
239239

240240
describe 'with android app' do
@@ -319,7 +319,7 @@ def stub_get_aab_info(integration_state = 'INTEGRATED')
319319
end
320320

321321
it 'crashes if it exceeds polling threshold' do
322-
stub_const('Fastlane::Actions::FirebaseAppDistributionAction::MAX_POLLING_RETRIES', 0)
322+
stub_const('Fastlane::Actions::FirebaseAppDistributionAction::UPLOAD_MAX_POLLING_RETRIES', 0)
323323
allow_any_instance_of(V1Api::FirebaseAppDistributionService)
324324
.to receive(:http)
325325
.and_return({ name: 'operation-name' }.to_json)

0 commit comments

Comments
 (0)