@@ -37,34 +37,23 @@ def self.run(params)
3737
3838 # TODO(lkellogg): This sets the send timeout for all POST requests made by the client, but
3939 # ideally the timeout should only apply to the binary upload
40- client = init_client ( params [ :service_credentials_file ] ,
41- params [ :firebase_cli_token ] ,
42- params [ :debug ] ,
43- timeout )
40+ client = init_v1_client ( params [ :service_credentials_file ] ,
41+ params [ :firebase_cli_token ] ,
42+ params [ :debug ] ,
43+ timeout )
4444
45- # If binary is an AAB, get the AAB info for this app, which includes the integration state and certificate data
45+ # If binary is an AAB, get the AAB info for this app, which includes the integration state
46+ # and certificate data
4647 if binary_type == :AAB
4748 aab_info = get_aab_info ( client , app_name )
4849 validate_aab_setup! ( aab_info )
4950 end
5051
5152 binary_type = binary_type_from_path ( binary_path )
5253 UI . message ( "⌛ Uploading the #{ binary_type } ." )
53-
54- # For some reason calling the client.upload_medium returns nil when
55- # it should return a long running operation object
56- # (https://github.com/googleapis/google-api-ruby-client/blob/main/generated/google-apis-firebaseappdistribution_v1/lib/google/apis/firebaseappdistribution_v1/service.rb#L79).
57- # We could use client.http, but is much slower
58- # (https://github.com/firebase/fastlane-plugin-firebase_app_distribution/issues/330),
59- # so we still use the old client for now.
60- # TODO(kbolay) Prefer client.upload_medium, assuming it is sufficiently fast
61- fad_api_client = Client ::FirebaseAppDistributionApiClient . new ( client . authorization . access_token , params [ :debug ] )
62- operation_name = fad_api_client . upload_binary ( app_name ,
63- binary_path ,
64- platform . to_s ,
65- get_upload_timeout ( params ) )
66-
67- release = poll_upload_release_operation ( client , operation_name , binary_type )
54+ operation = upload_binary ( app_name , binary_path , client , timeout )
55+ UI . message ( "🕵️ Validating upload." )
56+ release = poll_upload_release_operation ( client , operation , binary_type )
6857
6958 if binary_type == :AAB && aab_info && !aab_certs_included? ( aab_info . test_certificate )
7059 updated_aab_info = get_aab_info ( client , app_name )
@@ -86,6 +75,7 @@ def self.run(params)
8675 release . release_notes = Google ::Apis ::FirebaseappdistributionV1 ::GoogleFirebaseAppdistroV1ReleaseNotes . new (
8776 text : release_notes
8877 )
78+ UI . message ( "📜 Setting release notes." )
8979 release = update_release ( client , release )
9080 end
9181
@@ -98,6 +88,7 @@ def self.run(params)
9888 tester_emails : emails ,
9989 group_aliases : group_aliases
10090 )
91+ UI . message ( "📦 Distributing release." )
10192 distribute_release ( client , release , request )
10293 else
10394 UI . message ( "⏩ No testers or groups passed in. Skipping this step." )
@@ -222,8 +213,8 @@ def self.release_notes(params)
222213 release_notes_param || Actions . lane_context [ SharedValues ::FL_CHANGELOG ]
223214 end
224215
225- def self . poll_upload_release_operation ( client , operation_name , binary_type )
226- operation = client . get_project_app_release_operation ( operation_name )
216+ def self . poll_upload_release_operation ( client , operation , binary_type )
217+ operation = client . get_project_app_release_operation ( operation . name )
227218 MAX_POLLING_RETRIES . times do
228219 if operation . done && operation . response && operation . response [ 'release' ]
229220 release = extract_release ( operation )
@@ -257,6 +248,30 @@ def self.poll_upload_release_operation(client, operation_name, binary_type)
257248 extract_release ( operation )
258249 end
259250
251+ def self . upload_binary ( app_name , binary_path , client , timeout )
252+ options = Google ::Apis ::RequestOptions . new
253+ options . max_elapsed_time = timeout # includes retries (default = no retries)
254+ options . header = {
255+ 'Content-Type' => 'application/octet-stream' ,
256+ 'X-Goog-Upload-File-Name' => CGI . escape ( File . basename ( binary_path ) ) ,
257+ 'X-Goog-Upload-Protocol' => 'raw'
258+ }
259+
260+ # For some reason calling the client.upload_medium returns nil when
261+ # it should return a long running operation object, so we make a
262+ # standard http call instead and convert it to a long running object
263+ # https://github.com/googleapis/google-api-ruby-client/blob/main/generated/google-apis-firebaseappdistribution_v1/lib/google/apis/firebaseappdistribution_v1/service.rb#L79
264+ # TODO(kbolay) Prefer client.upload_medium
265+ response = client . http (
266+ :post ,
267+ "https://firebaseappdistribution.googleapis.com/upload/v1/#{ app_name } /releases:upload" ,
268+ body : File . open ( binary_path , 'rb' ) ,
269+ options : options
270+ )
271+
272+ Google ::Apis ::FirebaseappdistributionV1 ::GoogleLongrunningOperation . from_json ( response )
273+ end
274+
260275 def self . extract_release ( operation )
261276 Google ::Apis ::FirebaseappdistributionV1 ::GoogleFirebaseAppdistroV1Release . from_json ( operation . response [ 'release' ] . to_json )
262277 end
0 commit comments