-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
crashlytics.rb
114 lines (92 loc) 路 4.19 KB
/
crashlytics.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# TODO: Workaround, since crashlytics.rb from shenzhen includes the code for commander.
def command(_param)
end
module Fastlane
module Actions
class CrashlyticsAction < Action
def self.run(params)
require 'shenzhen'
require 'shenzhen/plugins/crashlytics'
assert_params_given!(params)
params = params.first
crashlytics_path = params[:crashlytics_path] || ENV["CRASHLYTICS_FRAMEWORK_PATH"]
api_token = params[:api_token] || ENV["CRASHLYTICS_API_TOKEN"]
build_secret = params[:build_secret] || ENV["CRASHLYTICS_BUILD_SECRET"]
ipa_path = params[:ipa_path] || Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]
notes_path = params[:notes_path]
emails = params[:emails]
notifications = params[:notifications]
# can pass groups param either as an Array or a String
case params[:groups]
when NilClass
groups = nil
when Array
groups = params[:groups].join(',')
when String
groups = params[:groups]
end
assert_valid_params!(crashlytics_path, api_token, build_secret, ipa_path)
Helper.log.info 'Uploading the IPA to Crashlytics. Go for a coffee 鈽曪笍.'.green
return if Helper.test?
client = Shenzhen::Plugins::Crashlytics::Client.new(crashlytics_path, api_token, build_secret)
response = client.upload_build(ipa_path, file: ipa_path, notes: notes_path, emails: emails, groups: groups, notifications: notifications)
if response
Helper.log.info 'Build successfully uploaded to Crashlytics'.green
else
Helper.log.fatal 'Error uploading to Crashlytics.'
raise 'Error when trying to upload ipa to Crashlytics'.red
end
end
private
def self.assert_params_given!(params)
return unless params.empty?
raise 'You have to pass Crashlytics parameters to the Crashlytics action, take a look at https://github.com/KrauseFx/fastlane#crashlytics'.red
end
def self.assert_valid_params!(crashlytics_path, api_token, build_secret, ipa_path)
assert_valid_crashlytics_path!(crashlytics_path)
assert_valid_api_token!(api_token)
assert_valid_build_secret!(build_secret)
assert_valid_ipa_path!(ipa_path)
end
def self.assert_valid_crashlytics_path!(crashlytics_path)
return if crashlytics_path && File.exist?(crashlytics_path)
raise "No Crashlytics path given or found, pass using `crashlytics_path: 'path'`".red
end
def self.assert_valid_api_token!(token)
return unless token.nil? || token.empty?
raise "No API token for Crashlytics given, pass using `api_token: 'token'`".red
end
def self.assert_valid_build_secret!(build_secret)
return unless build_secret.nil? || build_secret.empty?
raise "No build secret for Crashlytics given, pass using `build_secret: 'secret'`".red
end
def self.assert_valid_ipa_path!(ipa_path)
return if ipa_path && File.exist?(ipa_path)
raise "No IPA file given or found, pass using `ipa_path: 'path/app.ipa'`".red
end
def self.description
"Upload a new build to Crashlytics Beta"
end
def self.available_options
[
['crashlytics_path', 'Path to your Crashlytics bundle', 'CRASHLYTICS_FRAMEWORK_PATH'],
['api_token', 'Crashlytics Beta API Token', 'CRASHLYTICS_API_TOKEN'],
['build_secret', 'Crashlytics Build Secret', 'CRASHLYTICS_BUILD_SECRET'],
['ipa_path', 'Path to your IPA file. Optional if you use the `ipa` or `xcodebuild` action'],
['notes_path', 'Release Notes'],
['emails', 'Pass email address'],
['notifications', 'Crashlytics notification option']
]
end
def self.author
"pedrogimenez"
end
private_class_method :assert_params_given!,
:assert_valid_params!,
:assert_valid_crashlytics_path!,
:assert_valid_api_token!,
:assert_valid_build_secret!,
:assert_valid_ipa_path!
end
end
end