1
- require 'tempfile'
2
1
require 'fastlane/action'
3
2
require 'open3'
4
3
require 'shellwords'
4
+ require 'googleauth'
5
+ require_relative '../helper/upload_status_response'
5
6
require_relative '../helper/firebase_app_distribution_helper'
7
+ require_relative '../helper/firebase_app_distribution_error_message'
8
+ require_relative '../client/firebase_app_distribution_api_client'
9
+ require_relative '../helper/firebase_app_distribution_auth_client'
6
10
7
11
## TODO: should always use a file underneath? I think so.
8
12
## How should we document the usage of release notes?
9
13
module Fastlane
10
14
module Actions
11
15
class FirebaseAppDistributionAction < Action
12
- DEFAULT_FIREBASE_CLI_PATH = `which firebase`
13
16
FIREBASECMD_ACTION = "appdistribution:distribute" . freeze
14
17
18
+ extend Auth ::FirebaseAppDistributionAuthClient
15
19
extend Helper ::FirebaseAppDistributionHelper
16
20
17
21
def self . run ( params )
18
22
params . values # to validate all inputs before looking for the ipa/apk
19
- cmd = [ Shellwords . escape ( params [ :firebase_cli_path ] . chomp ) , FIREBASECMD_ACTION ]
20
- cmd << Shellwords . escape ( params [ :ipa_path ] || params [ :apk_path ] )
21
- if params [ :app ]
22
- cmd << "--app #{ params [ :app ] } "
23
- else
24
- platform = Actions . lane_context [ Actions ::SharedValues ::PLATFORM_NAME ]
25
- case platform
26
- when :android
27
- else
28
- archivePath = Actions . lane_context [ SharedValues ::XCODEBUILD_ARCHIVE ]
29
- if archivePath
30
- cmd << "--app"
31
- cmd << findout_ios_app_id_from_archive ( archivePath )
32
- end
23
+ auth_token = fetch_auth_token ( params [ :service_credentials_file ] , params [ :firebase_cli_token ] )
24
+ binary_path = params [ :ipa_path ] || params [ :apk_path ]
25
+ platform = lane_platform || platform_from_path ( binary_path )
26
+ fad_api_client = Client ::FirebaseAppDistributionApiClient . new ( auth_token , platform )
27
+
28
+ if params [ :app ] # Set app_id if it is specified as a parameter
29
+ app_id = params [ :app ]
30
+ elsif platform == :ios
31
+ archive_path = Actions . lane_context [ SharedValues ::XCODEBUILD_ARCHIVE ]
32
+ if archive_path
33
+ app_id = get_ios_app_id_from_archive ( archive_path )
33
34
end
34
35
end
35
36
36
- cmd << groups_flag ( params )
37
- cmd << testers_flag ( params )
38
- cmd << release_notes_flag ( params )
39
- cmd << flag_value_if_supplied ( '--token' , :firebase_cli_token , params )
40
- cmd << flag_if_supplied ( '--debug' , :debug , params )
41
-
42
- Actions . sh_control_output (
43
- cmd . compact . join ( " " ) ,
44
- print_command : false ,
45
- print_command_output : true
46
- )
47
- # make sure we do this, even in the case of an error.
48
- ensure
49
- cleanup_tempfiles
37
+ if app_id . nil?
38
+ UI . crash! ( ErrorMessage ::MISSING_APP_ID )
39
+ end
40
+ release_id = fad_api_client . upload ( app_id , binary_path , platform . to_s )
41
+ if release_id . nil?
42
+ return
43
+ end
44
+
45
+ release_notes = get_value_from_value_or_file ( params [ :release_notes ] , params [ :release_notes_file ] )
46
+ fad_api_client . post_notes ( app_id , release_id , release_notes )
47
+
48
+ testers = get_value_from_value_or_file ( params [ :testers ] , params [ :testers_file ] )
49
+ groups = get_value_from_value_or_file ( params [ :groups ] , params [ :groups_file ] )
50
+ emails = string_to_array ( testers )
51
+ group_ids = string_to_array ( groups )
52
+ fad_api_client . enable_access ( app_id , release_id , emails , group_ids )
53
+ UI . success ( "🎉 App Distribution upload finished successfully." )
50
54
end
51
55
52
56
def self . description
53
57
"Release your beta builds with Firebase App Distribution"
54
58
end
55
59
56
60
def self . authors
57
- [ "Stefan Natchev" ]
61
+ [ "Stefan Natchev" , "Manny Jimenez Github: mannyjimenez0810, Alonso Salas Infante Github: alonsosalasinfante" ]
58
62
end
59
63
60
64
# supports markdown.
61
65
def self . details
62
66
"Release your beta builds with Firebase App Distribution"
63
67
end
64
68
65
- def self . available_options
66
- platform = Actions . lane_context [ Actions ::SharedValues ::PLATFORM_NAME ]
69
+ def self . lane_platform
70
+ Actions . lane_context [ Actions ::SharedValues ::PLATFORM_NAME ]
71
+ end
67
72
68
- if platform == :ios || platform . nil?
73
+ def self . platform_from_path ( binary_path )
74
+ return nil unless binary_path
75
+ case binary_path . split ( '.' ) . last
76
+ when 'ipa'
77
+ :ios
78
+ when 'apk'
79
+ :android
80
+ end
81
+ end
82
+
83
+ def self . available_options
84
+ if lane_platform == :ios || lane_platform . nil?
69
85
ipa_path_default = Dir [ "*.ipa" ] . sort_by { |x | File . mtime ( x ) } . last
70
86
end
71
87
72
- if platform == :android
88
+ if lane_platform == :android
73
89
apk_path_default = Dir [ "*.apk" ] . last || Dir [ File . join ( "app" , "build" , "outputs" , "apk" , "app-release.apk" ) ] . last
74
90
end
75
91
@@ -100,22 +116,10 @@ def self.available_options
100
116
optional : true ,
101
117
type : String ) ,
102
118
FastlaneCore ::ConfigItem . new ( key : :firebase_cli_path ,
119
+ deprecated : "This plugin no longer uses the Firebase CLI" ,
103
120
env_name : "FIREBASEAPPDISTRO_FIREBASE_CLI_PATH" ,
104
121
description : "The absolute path of the firebase cli command" ,
105
- default_value : DEFAULT_FIREBASE_CLI_PATH ,
106
- default_value_dynamic : true ,
107
- optional : false ,
108
- type : String ,
109
- verify_block : proc do |value |
110
- value . chomp!
111
- if value . to_s == "" || !File . exist? ( value )
112
- UI . user_error! ( "firebase_cli_path: missing path to firebase cli tool. Please install firebase in $PATH or specify path" )
113
- end
114
-
115
- unless is_firebasecmd_supported? ( value )
116
- UI . user_error! ( "firebase_cli_path: `#{ value } ` does not support the `#{ FIREBASECMD_ACTION } ` command. Please download (https://appdistro.page.link/firebase-cli-download) or specify the path to the correct version of firebse" )
117
- end
118
- end ) ,
122
+ type : String ) ,
119
123
FastlaneCore ::ConfigItem . new ( key : :groups ,
120
124
env_name : "FIREBASEAPPDISTRO_GROUPS" ,
121
125
description : "The groups used for distribution, separated by commas" ,
@@ -156,7 +160,11 @@ def self.available_options
156
160
description : "Print verbose debug output" ,
157
161
optional : true ,
158
162
default_value : false ,
159
- is_string : false )
163
+ is_string : false ) ,
164
+ FastlaneCore ::ConfigItem . new ( key : :service_credentials_file ,
165
+ description : "Path to Google service account json" ,
166
+ optional : true ,
167
+ type : String )
160
168
]
161
169
end
162
170
@@ -178,18 +186,6 @@ def self.example_code
178
186
CODE
179
187
]
180
188
end
181
-
182
- ## TODO: figure out if we can surpress color output.
183
- def self . is_firebasecmd_supported? ( cmd )
184
- outerr , status = Open3 . capture2e ( cmd , "--non-interactive" , FIREBASECMD_ACTION , "--help" )
185
- return false unless status . success?
186
-
187
- if outerr =~ /is not a Firebase command/
188
- return false
189
- end
190
-
191
- true
192
- end
193
189
end
194
190
end
195
191
end
0 commit comments