@@ -5,13 +5,22 @@ module Fastlane
55 module Actions
66 class IosSendAppSizeMetricsAction < Action
77 def self . run ( params )
8+ # Check input parameters
9+ base_url = URI ( params [ :api_base_url ] )
10+ api_token = params [ :api_token ]
11+ if ( api_token . nil? || api_token . empty? ) && !base_url . is_a? ( URI ::File )
12+ UI . user_error! ( 'An API token is required when using an `api_base_url` with a scheme other than `file://`' )
13+ end
14+
15+ # Build the payload base
816 payload = Fastlane ::WPMRT ::AppSizeMetricsPayload . new (
917 'App Name' : params [ :app_name ] ,
1018 'Build Type' : params [ :build_type ] ,
1119 'App Version' : params [ :app_version ]
1220 )
1321 payload . add_metric ( name : 'File Size' , value : File . size ( params [ :ipa_path ] ) )
1422
23+ # Add app-thinning metrics to the payload if a `.plist` is provided
1524 app_thinning_plist_path = params [ :app_thinning_plist_path ] || File . join ( File . dirname ( params [ :ipa_path ] ) , 'app-thinning.plist' )
1625 if File . exist? ( app_thinning_plist_path )
1726 plist = Plist . parse_xml ( app_thinning_plist_path )
@@ -25,9 +34,10 @@ def self.run(params)
2534 end
2635 end
2736
37+ # Send the payload
2838 payload . send_metrics (
29- base_url : params [ :api_base_url ] ,
30- api_token : params [ : api_token]
39+ base_url : base_url ,
40+ api_token : api_token
3141 )
3242 end
3343
@@ -57,7 +67,7 @@ def self.available_options
5767 env_name : 'FL_IOS_SEND_APP_SIZE_METRICS_API_TOKEN' ,
5868 description : 'The bearer token to call to API' ,
5969 type : String ,
60- optional : false
70+ optional : true # Required unless `api_base_url` is a `file://` URL
6171 ) ,
6272 FastlaneCore ::ConfigItem . new (
6373 key : :app_name ,
0 commit comments