Class: OceanPackage::Command
- Inherits:
-
Object
- Object
- OceanPackage::Command
- Includes:
- TimeFlow::Mixin
- Defined in:
- lib/ocean_package/command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
命令参数.
-
#at_mobiles ⇒ Object
@ 的手机号.
-
#change_log ⇒ Object
本次更新内容.
-
#custom_ipa_file_path ⇒ Object
自定义的ipa文件路径.
-
#ding ⇒ Object
ding ding.
-
#fir ⇒ Object
fir 平台.
-
#oss ⇒ Object
oss 对象.
-
#package ⇒ Object
xcodebuild 打包相关.
-
#pgy ⇒ Object
蒲公英平台.
Instance Method Summary collapse
-
#compute_total_time ⇒ Object
总共时间,单位 秒 s.
-
#final_change_log ⇒ Object
最终的 change log.
-
#final_ipa_file_path ⇒ Object
最终的ipa文件路径.
-
#finished ⇒ Object
打包完成.
-
#has_custom_ipa_file ⇒ Object
是否设置了自定义的ipa文件.
-
#initialize(params = []) ⇒ Command
constructor
A new instance of Command.
-
#make_web_hook_message ⇒ Object
web hook 消息内容.
-
#make_web_hook_message_title ⇒ Object
web hook 消息标题.
-
#run ⇒ Object
运行.
-
#send_ding_talk_msg ⇒ Object
发送打包信息到钉钉.
-
#upload ⇒ Object
上传 ipa 文件.
-
#upload_qr_code(path, name) ⇒ Object
上传 二维码 QRCode 图片到 oss 后续其他平台,比如蒲公英也是需要类似的逻辑.
-
#upload_to_fir ⇒ Object
上传到 fir 平台.
-
#upload_to_pgy ⇒ Object
—— pgy 平台 ——-.
- #write_time_flow_data ⇒ Object
Methods included from TimeFlow::Mixin
Constructor Details
#initialize(params = []) ⇒ Command
Returns a new instance of Command.
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 |
# File 'lib/ocean_package/command.rb', line 30 def initialize(params = []) argv = CLAide::ARGV.new(params) @arguments = argv.arguments Log.info("arguments: #{@arguments}") workspace_path = argv.option("workspace-path", "") Log.info("workspace_path: #{workspace_path}") scheme = argv.option("scheme", "") Log.info("scheme: #{scheme}") # 默认配置改为空,防止包环境错误 configuration = argv.option("configuration", "") Log.info("configuration: #{configuration}") archive_path = argv.option("archive-path", OceanPackage::Constants::DEFAULT_ARCHIVE_PATH) Log.info("archive_path: #{archive_path}") company_name = argv.option("company-name", OceanPackage::Constants::DEFAULT_COMPANY_NAME) Log.info("company_name: #{company_name}") = argv.option("export-options-plist", "") Log.info("export_options_plist: #{export_options_plist}") ##### 自定义的 ipa 文件 ##### ipa_file_path = argv.option("ipa-file-path", "") Log.info("ipa_file_path: #{ipa_file_path}") @custom_ipa_file_path = ipa_file_path extra_export_params = argv.option("extra-export-params", "") Log.info("extra-export-params: #{extra_export_params}") open_finder = argv.flag?("open-finder", false ) Log.info("open-finder: #{open_finder}") # 自定义ipa文件,使用该文件作为 archive path tmp_archive_path = has_custom_ipa_file ? File.dirname("#{ipa_file_path}") : archive_path Log.info("tmp_archive_path: #{tmp_archive_path}") @package = OceanPackage::Package.new(workspace_path, scheme, configuration, tmp_archive_path, company_name, , extra_export_params, open_finder) fir_token = argv.option("fir-token", "") Log.info("fir_token: #{fir_token}") change_log = argv.option("change-log", "") @change_log = change_log Log.info("change_log: #{change_log}") fir_log_path = @package.final_archive_path + 'fir.log' @fir = OceanPackage::Fir.new(fir_token, final_change_log, final_ipa_file_path, fir_log_path) ##### 蒲公英 ##### pgy_api_key = argv.option("pgy-api-key", "") @pgy = OceanPackage::Pgy.new(pgy_api_key, final_change_log, final_ipa_file_path) Log.info("pgy_api_key: #{pgy_api_key}") ##### oss ##### oss_bucket_name = argv.option("oss-bucket-name", "") Log.info("oss_bucket_name: #{oss_bucket_name}") oss_bucket_path = argv.option("oss-bucket-path", "") Log.info("oss_bucket_path: #{oss_bucket_path}") oss_endpoint = argv.option("oss-endpoint", "") Log.info("oss_endpoint: #{oss_endpoint}") @oss = OceanPackage::Oss.new(oss_bucket_name, oss_bucket_path, oss_endpoint) ding_token = argv.option("ding-token", "") Log.info("ding_token: #{ding_token}") at_mobiles = argv.option("at-mobiles", "").split(",") Log.info("ding_at_mobiles: #{at_mobiles}") @at_mobiles = at_mobiles @ding = OceanPackage::DingTalk.new(ding_token) end |
Instance Attribute Details
#arguments ⇒ Object
命令参数
18 19 20 |
# File 'lib/ocean_package/command.rb', line 18 def arguments @arguments end |
#at_mobiles ⇒ Object
@ 的手机号
24 25 26 |
# File 'lib/ocean_package/command.rb', line 24 def at_mobiles @at_mobiles end |
#change_log ⇒ Object
本次更新内容
21 22 23 |
# File 'lib/ocean_package/command.rb', line 21 def change_log @change_log end |
#custom_ipa_file_path ⇒ Object
自定义的ipa文件路径
27 28 29 |
# File 'lib/ocean_package/command.rb', line 27 def custom_ipa_file_path @custom_ipa_file_path end |
#ding ⇒ Object
ding ding
15 16 17 |
# File 'lib/ocean_package/command.rb', line 15 def ding @ding end |
#fir ⇒ Object
fir 平台
9 10 11 |
# File 'lib/ocean_package/command.rb', line 9 def fir @fir end |
#oss ⇒ Object
oss 对象
13 14 15 |
# File 'lib/ocean_package/command.rb', line 13 def oss @oss end |
#package ⇒ Object
xcodebuild 打包相关
7 8 9 |
# File 'lib/ocean_package/command.rb', line 7 def package @package end |
#pgy ⇒ Object
蒲公英平台
11 12 13 |
# File 'lib/ocean_package/command.rb', line 11 def pgy @pgy end |
Instance Method Details
#compute_total_time ⇒ Object
总共时间,单位 秒 s
180 181 182 183 184 185 186 187 188 |
# File 'lib/ocean_package/command.rb', line 180 def compute_total_time time1 = package.start_time time2 = Time.now seconds = time2 - time1 Log.info("total time: #{seconds}") seconds end |
#final_change_log ⇒ Object
最终的 change log
109 110 111 112 113 114 115 |
# File 'lib/ocean_package/command.rb', line 109 def final_change_log if @change_log.empty? syscall('git log --pretty=format:%s -1') else @change_log end end |
#final_ipa_file_path ⇒ Object
最终的ipa文件路径
123 124 125 |
# File 'lib/ocean_package/command.rb', line 123 def final_ipa_file_path has_custom_ipa_file ? "#{@custom_ipa_file_path}" : @package.ipa_file_path end |
#finished ⇒ Object
打包完成
232 233 234 235 236 237 238 239 |
# File 'lib/ocean_package/command.rb', line 232 def finished time_flow.point_end_time write_time_flow_data Log.divider Log.info("package finished") Log.divider end |
#has_custom_ipa_file ⇒ Object
是否设置了自定义的ipa文件
118 119 120 |
# File 'lib/ocean_package/command.rb', line 118 def has_custom_ipa_file "#{@custom_ipa_file_path}".empty? ? false : true end |
#make_web_hook_message ⇒ Object
web hook 消息内容
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/ocean_package/command.rb', line 196 def ipa = OceanPackage::Ipa.new(final_ipa_file_path) ipa.run # markdown 格式 content = "# #{ipa.display_name} \n\n" content += "当前平台: iOS \n\n" content += "APP名称: " + ipa.display_name + "\n\n" content += "当前版本: " + ipa.version + "(#{ipa.build_version})" + "\n\n" content += "打包耗时: " + "#{compute_total_time}" + "s" + "\n\n" content += "发布环境: " + "#{package.configuration}" + "\n\n" content += "更新描述: " + final_change_log + "\n\n" content += "发布时间: " + Time.new.strftime("%Y年%m月%d日 %H时%M分%S秒") + "\n\n" content += "下载链接: [点我](#{@ipa_download_link})" + "\n\n" content += "" Log.divider Log.info("web hook message: \n#{content}") Log.divider content end |
#make_web_hook_message_title ⇒ Object
web hook 消息标题
191 192 193 |
# File 'lib/ocean_package/command.rb', line 191 def "iOS 来新包啦~" end |
#run ⇒ Object
运行
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ocean_package/command.rb', line 128 def run time_flow.point_start_time # 没有自定义ipa文件,需要执行打包命令 unless has_custom_ipa_file package.run end upload send_ding_talk_msg finished end |
#send_ding_talk_msg ⇒ Object
发送打包信息到钉钉
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ocean_package/command.rb', line 220 def send_ding_talk_msg time_flow.point_notify_group_time # 消息卡片,富文本 title = content = ding.(title, content) ding.(title, @at_mobiles) end |
#upload ⇒ Object
上传 ipa 文件
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ocean_package/command.rb', line 140 def upload time_flow.point_upload_ipa_time can_fir = fir.check can_pgy = pgy.check if can_fir Log.info("publish platform: fir") upload_to_fir elsif can_pgy Log.info("publish platform: pgy") upload_to_pgy else Log.info("publish platform: none, exit") exit(1) end end |
#upload_qr_code(path, name) ⇒ Object
上传 二维码 QRCode 图片到 oss 后续其他平台,比如蒲公英也是需要类似的逻辑
168 169 170 |
# File 'lib/ocean_package/command.rb', line 168 def upload_qr_code(path, name) @qr_code_url = oss.upload(path, name) end |
#upload_to_fir ⇒ Object
上传到 fir 平台
160 161 162 163 164 |
# File 'lib/ocean_package/command.rb', line 160 def upload_to_fir fir.run upload_qr_code(fir.find_qr_code_path, fir.find_release_id) @ipa_download_link = fir.whole_download_link end |
#upload_to_pgy ⇒ Object
—— pgy 平台 ——-
173 174 175 176 177 |
# File 'lib/ocean_package/command.rb', line 173 def upload_to_pgy pgy.run @qr_code_url = pgy.get_qr_code_url @ipa_download_link = pgy.get_download_url end |
#write_time_flow_data ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ocean_package/command.rb', line 241 def write_time_flow_data time_flow_dir = @package.final_archive_path time_flow_file_path = "#{time_flow_dir}timeflow.json" params = time_flow.make_all_points params['timeFlowPath'] = time_flow_file_path json = JSON.dump(params) unless File.exist?(time_flow_file_path) FileUtils.touch(time_flow_file_path) end a_file = File.new(time_flow_file_path, "r+") if a_file a_file.syswrite(json) Log.info("write time flow to path(success): #{time_flow_file_path}") else Log.error("write time flow to path(fail): #{time_flow_file_path}") end end |