使用Fastlane打包上传到蒲公英, 同步发送钉钉机器人消息(加签ruby实现)
修改配置更改xxx即可, 都有注释
# 指定ipa名字, 以时间命名 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'
}
# 指定钉钉群, 可指定多个
ding_talk_robots = [ding_talk_config1, ding_talk_config2]
导出ipa, 供上传到第三方平台,Fir, 蒲公英使用
注意configuration 为项目中的.xcconfig名字, Xcode 默认有两个Debug和Release, 按需配置
xcconfig文件
# 导出ipa, 供上传到第三方平台,Fir, 蒲公英使用
# 注意configuration 为项目中的.xcconfig名字, Xcode 默认有两个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
发送钉钉机器人消息, 包含加签实现
# 钉钉机器人
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
# 配置钉钉机器人消息内容
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-内测版应用更新
> 版本信息:#{app_version}(Build #{app_build_version})\n
> 应用大小:#{formatted_file_size} MB\n
> 更新时间:#{time_now}\n
> 关键词:发版专用\n
> 更新内容:#{update_log}\n
iPhone相机扫描二维码下载:
![二维码](#{pgy_qrcode})\n
[点我进入主页下载](#{pgy_app_url}) #{contacts_format}
EOF
markdown = {
msgtype: "markdown",
markdown: {
title: "#{app_name}iOS内测更新",
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"]
# 计算签名
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)
# 发送钉钉消息
sendNotifyToDingTalk(is_use_previous_ipa: false)
end
记得安装fastlane蒲公英插件
fastlane add_plugin pgyer
最终效果
image.png
网友评论