-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathupdate_app_to_bugly.rb
202 lines (184 loc) · 8.33 KB
/
update_app_to_bugly.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
module Fastlane
module Actions
module SharedValues
UPDATE_APP_TO_BUGLY_DOWNLOAD_URL = :UPDATE_APP_TO_BUGLY_DOWNLOAD_URL
end
# To share this integration with the other fastlane users:
# - Fork https://github.com/fastlane/fastlane/tree/master/fastlane
# - Clone the forked repository
# - Move this integration into lib/fastlane/actions
# - Commit, push and submit the pull request
class UpdateAppToBuglyAction < Action
def self.run(params)
require 'json'
UI.message "file path: #{params[:file_path]}"
json_file = 'update_app_to_bugly_result.json'
begin
secret = ''
if !params[:secret].nil? && !params[:secret].empty?
secret = " -F \"secret=#{params[:secret]}\" "
UI.message "secret:#{secret}"
end
rescue Exception => e
UI.message "error at checking secret,caused by #{e}"
return
end
begin
title = ''
if !params[:title].nil? && !params[:title].to_s.empty?
title = " -F \"title=#{params[:title]}\" "
UI.message "title:#{title}"
end
rescue Exception => e
UI.message "error at checking title,caused by #{e}"
return
end
begin
desc = ''
if !params[:desc].nil? && !params[:desc].to_s.empty?
desc = " -F \"description=#{params[:desc]}\" "
UI.message "desc:#{desc}"
end
rescue Exception => e
UI.message "error at checking desc,caused by #{e}"
return
end
begin
users = ''
if !params[:users].nil? && !params[:users].empty?
users = " -F \"users=#{params[:users]}\" "
UI.message "users:#{users}"
end
rescue Exception => e
UI.message "error at checking users,caused by #{e}"
return
end
begin
password = ''
if !params[:password].nil? && !params[:password].empty?
password = " -F \"password=#{params[:password]}\" "
UI.message "password:#{password}"
end
rescue Exception => e
UI.message "error at checking password,caused by #{e}"
return
end
begin
download_limit = ''
if !params[:download_limit].nil? && params[:download_limit] > 0
download_limit = " -F \"download_limit=#{params[:download_limit]}\" "
UI.message "download_limit:#{download_limit}"
end
rescue Exception => e
UI.message "error at checking download_limit,caused by #{e}"
return
end
cmd = "curl --insecure -X \"PUT\" -F \"file=@#{params[:file_path]}\" -F \"exp_id=#{params[:exp_id]}\"" + title + desc + secret + users + password + download_limit + "https://api.bugly.qq.com/beta/apiv1/exp?app_key=#{params[:app_key]} -o " + json_file
sh(cmd)
obj = JSON.parse(File.read(json_file))
ret = obj['rtcode']
if ret == 0
UI.message "update success"
url = obj['data']['url']
Actions.lane_context[SharedValues::UPDATE_APP_TO_BUGLY_DOWNLOAD_URL] = url
else
UI.message "update failed,result is #{obj}"
end
end
#####################################################
# @!group Documentation
#####################################################
def self.description
'A short description with <= 80 characters of what this action does'
end
def self.details
# Optional:
# this is your chance to provide a more detailed description of this action
'You can use this action to do cool things...'
end
def self.available_options
# Define all options your action supports.
# Below a few examples
[
FastlaneCore::ConfigItem.new(key: :file_path,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_FILE_PATH',
description: 'file path for UploadAppToBuglyAction',
is_string: true,
verify_block: proc do |value|
UI.user_error!("No file path for UploadAppToBuglyAction given, pass using `file_path: 'path'`") unless value && !value.empty?
UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
end),
FastlaneCore::ConfigItem.new(key: :app_key,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_APP_KEY',
description: 'app key for UploadAppToBuglyAction',
is_string: true,
verify_block: proc do |value|
UI.user_error!("NO app_key for UploadAppToBuglyAction given, pass using `app_key: 'app_key'`") unless value && !value.empty?
end),
FastlaneCore::ConfigItem.new(key: :exp_id,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_EXP_ID',
description: 'exp id for UploadAppToBuglyAction',
is_string: true,
verify_block: proc do |value|
UI.user_error!("No exp_id for UploadAppToBuglyAction given, pass using `exp_id: 'exp_id'`") unless value && !value.empty?
end),
FastlaneCore::ConfigItem.new(key: :title,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_TITLE',
description: 'title for UploadAppToBuglyAction',
is_string: true,
default_value: ''),
FastlaneCore::ConfigItem.new(key: :desc,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_DESC',
description: 'desc for UploadAppToBuglyAction',
is_string: true,
default_value: 'description'),
FastlaneCore::ConfigItem.new(key: :secret,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_DESCRIPTION',
description: 'secret for UploadAppToBuglyAction',
is_string: true,
default_value: ''),
FastlaneCore::ConfigItem.new(key: :users,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_DESCRIPTION',
description: 'users for UploadAppToBuglyAction',
is_string: true,
default_value: ''),
FastlaneCore::ConfigItem.new(key: :password,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_DESCRIPTION',
description: 'password for UploadAppToBuglyAction',
is_string: true,
default_value: ''),
FastlaneCore::ConfigItem.new(key: :download_limit,
env_name: 'FL_UPLOAD_APP_TO_BUGLY_DESCRIPTION',
description: 'download_limit for UploadAppToBuglyAction',
is_string: false,
default_value: 10_000)
]
end
def self.output
# Define the shared values you are going to provide
# Example
[
['UPDATE_APP_TO_BUGLY_DOWNLOAD_URL', 'download url']
]
end
def self.return_value
# If you method provides a return value, you can describe here what it does
end
def self.authors
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
["pudgeli"]
end
def self.is_supported?(platform)
# you can do things like
#
# true
#
# platform == :ios
#
# [:ios, :mac].include?(platform)
#
platform == :ios
end
end
end
end