@@ -5,13 +5,22 @@ module Fastlane
5
5
module Actions
6
6
class IosSendAppSizeMetricsAction < Action
7
7
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
8
16
payload = Fastlane ::WPMRT ::AppSizeMetricsPayload . new (
9
17
'App Name' : params [ :app_name ] ,
10
18
'Build Type' : params [ :build_type ] ,
11
19
'App Version' : params [ :app_version ]
12
20
)
13
21
payload . add_metric ( name : 'File Size' , value : File . size ( params [ :ipa_path ] ) )
14
22
23
+ # Add app-thinning metrics to the payload if a `.plist` is provided
15
24
app_thinning_plist_path = params [ :app_thinning_plist_path ] || File . join ( File . dirname ( params [ :ipa_path ] ) , 'app-thinning.plist' )
16
25
if File . exist? ( app_thinning_plist_path )
17
26
plist = Plist . parse_xml ( app_thinning_plist_path )
@@ -25,9 +34,10 @@ def self.run(params)
25
34
end
26
35
end
27
36
37
+ # Send the payload
28
38
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
31
41
)
32
42
end
33
43
@@ -57,7 +67,7 @@ def self.available_options
57
67
env_name : 'FL_IOS_SEND_APP_SIZE_METRICS_API_TOKEN' ,
58
68
description : 'The bearer token to call to API' ,
59
69
type : String ,
60
- optional : false
70
+ optional : true # Required unless `api_base_url` is a `file://` URL
61
71
) ,
62
72
FastlaneCore ::ConfigItem . new (
63
73
key : :app_name ,
0 commit comments