使用Fastlane打包上傳到蒲公英, 同步發(fā)送釘釘機(jī)器人消息(加簽ruby實(shí)現(xiàn))
修改配置更改xxx即可, 都有注釋
# 指定ipa名字, 以時(shí)間命名 2020-05-21 04/52/06.ipa
time_now = Time.now.strftime(“%Y-%m-%d %H:%M:%S”)
# 釘釘更新日志
update_log = '更新日志xxx'
# pger所屬
pgyer_ower = "1"
=begin
蒲公英賬號配置
pgy_app_url app蒲公英下載地址
pgy_user_key
pgy_qrcode app蒲公英下載二維碼
=end
pgyer_config = {
"1" => {
"pgy_app_url" => "https://www.pgyer.com/xxx",
"pgy_api_key" => "xxx",
"pgy_user_key" => "xxx",
"pgy_qrcode" => "https://www.pgyer.com/app/qrcode/xxx"
},
"2" => {
"pgy_app_url" => "https://www.pgyer.com/xxx",
"pgy_api_key" => "xxx",
"pgy_user_key" => "xxx",
"pgy_qrcode" => "https://www.pgyer.com/app/qrcode/xxx"
},
"3" => {
"pgy_app_url" => "https://www.pgyer.com/xxx",
"pgy_api_key" => "xxx",
"pgy_user_key" => "xxx",
"pgy_qrcode" => "https://www.pgyer.com/app/qrcode/xxx"
}
}
current_pgy_config = pgyer_config[pgyer_ower]
pgy_app_url = current_pgy_config['pgy_app_url']
pgy_api_key = current_pgy_config['pgy_api_key']
pgy_user_key = current_pgy_config['pgy_user_key']
pgy_qrcode = current_pgy_config['pgy_qrcode']
=begin
釘釘群配置
ding_talk_url Webhook地址
ding_talk_secret 加簽的secret
contacts 要@的同事的號碼
=end
# 群1
ding_talk_config1 = {
"ding_talk_url" => "https://oapi.dingtalk.com/robot/send?access_token=xxx",
"contacts" => ["xxx"],
"ding_talk_secret" => 'xxx'
}
# 群2
ding_talk_config2 = {
"ding_talk_url" => "https://oapi.dingtalk.com/robot/send?access_token=xxx",
"contacts" => ["xxx"],
"ding_talk_secret" => 'xxx'
}
# 群3
ding_talk_config3 = {
"ding_talk_url" => "https://oapi.dingtalk.com/robot/send?access_token=xxx",
"contacts" => ["xxx"],
"ding_talk_secret" => 'xxx'
}
# 指定釘釘群, 可指定多個(gè)
ding_talk_robots = [ding_talk_config1, ding_talk_config2]
導(dǎo)出ipa, 供上傳到第三方平臺,Fir, 蒲公英使用
注意configuration 為項(xiàng)目中的.xcconfig名字, Xcode 默認(rèn)有兩個(gè)Debug和Release, 按需配置
xcconfig文件
# 導(dǎo)出ipa, 供上傳到第三方平臺,Fir, 蒲公英使用
# 注意configuration 為項(xiàng)目中的.xcconfig名字, Xcode 默認(rèn)有兩個(gè)Debug和Release, 按需配置
lane :exportAdHocIpa do
increment_build_number
gym(
silent:true,
export_method: "ad-hoc",
output_directory: "./ipa/AdHoc",
configuration: "AdHoc",
output_name: "#{time_now}.ipa",
include_bitcode: false,
export_options: {
uploadBitcode: false,
uploadSymbols: false,
compileBitcode: false
}
)
end
發(fā)送釘釘機(jī)器人消息, 包含加簽實(shí)現(xiàn)
# 釘釘機(jī)器人
lane :sendNotifyToDingTalk do |options|
# ipa路徑
app_patch = lane_context[SharedValues::IPA_OUTPUT_PATH]
# app版本號
app_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleShortVersionString")
# appbuild號
app_build_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleVersion")
# app名字
app_name = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleDisplayName")
# 包大小
compressed_file_size = File.size(File.absolute_path(app_patch)).to_f / 2**20
formatted_file_size = '%.2f' % compressed_file_size
# 配置釘釘機(jī)器人消息內(nèi)容
ding_talk_robots.each{|item|
contacts_format = ""
item["contacts"].each{|contact|
phone = ' @' + contact
contacts_format = contacts_format + phone
}
ding_talk_update_text = <<-EOF
#### #{app_name}iOS-內(nèi)測版應(yīng)用更新
> 版本信息:#{app_version}(Build #{app_build_version})\n
> 應(yīng)用大小:#{formatted_file_size} MB\n
> 更新時(shí)間:#{time_now}\n
> 關(guān)鍵詞:發(fā)版專用\n
> 更新內(nèi)容:#{update_log}\n
iPhone相機(jī)掃描二維碼下載:
![二維碼](#{pgy_qrcode})\n
[點(diǎn)我進(jìn)入主頁下載](#{pgy_app_url}) #{contacts_format}
EOF
markdown = {
msgtype: "markdown",
markdown: {
title: "#{app_name}iOS內(nèi)測更新",
text: ding_talk_update_text,
},
at: {
atMobiles:item["contacts"],
isAtAll: false
}
}
ding_talk_url = item["ding_talk_url"]
ding_talk_secret = item["ding_talk_secret"]
# 計(jì)算簽名
timestamp = DateTime.now.strftime('%Q')
finaly_sign = ''
if ding_talk_secret
data = timestamp + "\n" + ding_talk_secret
digest = OpenSSL::Digest.new('SHA256')
sign_data = OpenSSL::HMAC.digest(digest, ding_talk_secret.force_encoding("UTF-8"), data.force_encoding("UTF-8"))
finaly_sign = Base64.encode64(sign_data).gsub("\n",'')
finaly_sign = CGI::escape(finaly_sign)
end
ding_talk_url = ding_talk_url + "×tamp=#{timestamp}&sign=#{finaly_sign}"
puts ding_talk_url
uri = URI.parse(ding_talk_url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
request.body = markdown.to_json
puts request
response = https.request(request)
puts "------------------------------"
puts "Response #{response.code} #{response.message}: #{response.body}"
}
end
打包 到蒲公英
# 打包 到蒲公英
lane :deliverToPGY do
# 打出ipa包
exportAdHocIpa
# 上傳到蒲公英
pgyer(api_key: pgy_api_key, user_key: pgy_user_key)
# 發(fā)送釘釘消息
sendNotifyToDingTalk(is_use_previous_ipa: false)
end
記得安裝fastlane蒲公英插件
fastlane add_plugin pgyer
最終效果
image.png