Class: OceanPackage::Command
- Inherits:
-
Object
- Object
- OceanPackage::Command
- Defined in:
- lib/ocean_package/command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
命令参数.
-
#at_mobiles ⇒ Object
@ 的手机号.
-
#change_log ⇒ Object
本次更新内容.
-
#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.
-
#finished ⇒ Object
打包完成.
-
#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 平台 ——-.
Constructor Details
#initialize(params = []) ⇒ Command
Returns a new instance of Command.
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 |
# File 'lib/ocean_package/command.rb', line 25 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", OceanPackage::Constants::DEFAULT_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}") @package = OceanPackage::Package.new(workspace_path, scheme, configuration, archive_path, company_name, ) 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, @package.ipa_file_path, fir_log_path) ##### 蒲公英 ##### pgy_api_key = argv.option("pgy-api-key", "") @pgy = OceanPackage::Pgy.new(pgy_api_key, final_change_log, @package.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
命令参数
17 18 19 |
# File 'lib/ocean_package/command.rb', line 17 def arguments @arguments end |
#at_mobiles ⇒ Object
@ 的手机号
23 24 25 |
# File 'lib/ocean_package/command.rb', line 23 def at_mobiles @at_mobiles end |
#change_log ⇒ Object
本次更新内容
20 21 22 |
# File 'lib/ocean_package/command.rb', line 20 def change_log @change_log end |
#ding ⇒ Object
ding ding
14 15 16 |
# File 'lib/ocean_package/command.rb', line 14 def ding @ding end |
#fir ⇒ Object
fir 平台
8 9 10 |
# File 'lib/ocean_package/command.rb', line 8 def fir @fir end |
#oss ⇒ Object
oss 对象
12 13 14 |
# File 'lib/ocean_package/command.rb', line 12 def oss @oss end |
#package ⇒ Object
xcodebuild 打包相关
6 7 8 |
# File 'lib/ocean_package/command.rb', line 6 def package @package end |
#pgy ⇒ Object
蒲公英平台
10 11 12 |
# File 'lib/ocean_package/command.rb', line 10 def pgy @pgy end |
Instance Method Details
#compute_total_time ⇒ Object
总共时间,单位 秒 s
143 144 145 146 147 148 149 150 151 |
# File 'lib/ocean_package/command.rb', line 143 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
89 90 91 92 93 94 95 |
# File 'lib/ocean_package/command.rb', line 89 def final_change_log if @change_log.empty? syscall('git log --pretty=format:%s -1') else @change_log end end |
#finished ⇒ Object
打包完成
193 194 195 196 197 |
# File 'lib/ocean_package/command.rb', line 193 def finished Log.divider Log.info("package finished") Log.divider end |
#make_web_hook_message ⇒ Object
web hook 消息内容
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ocean_package/command.rb', line 159 def ipa = OceanPackage::Ipa.new(package.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 消息标题
154 155 156 |
# File 'lib/ocean_package/command.rb', line 154 def "iOS 来新包啦~" end |
#run ⇒ Object
97 98 99 100 101 102 |
# File 'lib/ocean_package/command.rb', line 97 def run package.run upload send_ding_talk_msg finished end |
#send_ding_talk_msg ⇒ Object
发送打包信息到钉钉
183 184 185 186 187 188 189 190 |
# File 'lib/ocean_package/command.rb', line 183 def send_ding_talk_msg # 消息卡片,富文本 title = content = ding.(title, content) ding.(title, @at_mobiles) end |
#upload ⇒ Object
上传 ipa 文件
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ocean_package/command.rb', line 105 def upload 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 后续其他平台,比如蒲公英也是需要类似的逻辑
131 132 133 |
# File 'lib/ocean_package/command.rb', line 131 def upload_qr_code(path, name) @qr_code_url = oss.upload(path, name) end |
#upload_to_fir ⇒ Object
上传到 fir 平台
123 124 125 126 127 |
# File 'lib/ocean_package/command.rb', line 123 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 平台 ——-
136 137 138 139 140 |
# File 'lib/ocean_package/command.rb', line 136 def upload_to_pgy pgy.run @qr_code_url = pgy.get_qr_code_url @ipa_download_link = pgy.get_download_url end |