打包脚本集成
- 定义好可配置项,方便修改
1 | # 先定义好全局变量 |
打包到Testflight
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24desc "打包到Testflight"
lane :beta do
increment_build_number_in_plist(target: SCHEME) #build号自增
build_app(
workspace: WORKSPACE,
scheme: SCHEME,
silent: true,
clean: true,
output_directory: '.ipa/Testflight',
output_name: 'app.ipa',
export_xcargs: "-allowProvisioningUpdates",
export_options: {
method: 'app-store',
manifest: {
appURL: 'https://example.com/MyApp.ipa',
displayImageURL: 'http://xxxxxx',#小图标
fullSizeImageURL: 'http://xxxxx'#大图标1024x1024
}
}
)
upload_to_testflight(
ipa: '.ipa/Testflight/app.ipa'
)
end打包到App Store
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
29desc "部署到App Store"
lane :release do |options|
sigh(
output_path: '.certificates',
force: true
)
increment_version_number_in_plist(
target: SCHEME,
version_number: options[:version_number]
)
increment_build_number_in_plist(target: SCHEME)
gym(
scheme: SCHEME,
clean: true,
silent: true,
output_directory: '.ipa/AppStore',
output_name: 'app.ipa',
configuration: 'Release',
export_xcargs: "-allowProvisioningUpdates"
)
upload_to_app_store(
force: true,
ipa: '.ipa/AppStore/app.ipa',
skip_screenshots: true,
automatic_release: true
)
end打AdHoc分发包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24cert #获取证书
#验证签名
sigh(
adhoc: true,
output_path: '.certificates',
app_identifier: BundleId
)
#自增build号
increment_build_number_in_plist(target: SCHEME)
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
#编译打包
gym(
scheme: SCHEME,
clean: true,
output_directory: ".ipa/#{SCHEME}/#{time}",
output_name: 'app.ipa',
configuration: "Release",
export_xcargs: "-allowProvisioningUpdates"
)
# 上传蒲公英
upload_ipa_to_pgyer(scheme: SCHEME, time: time)
# 发送钉钉消息
send_dingding_msg()上传至蒲公英分发平台 (这个平时用的比较多)
1
2
3
4
5
6
7private_lane :upload_ipa_to_pgyer do |options|
pgyer(
api_key: "xxxxx",
user_key: "xxxxx",
ipa: ".ipa/#{options[:scheme]}/#{options[:time]}/app.ipa"
)
end
发送钉钉机器人消息
1
2
3
4
5
6desc "发送机器人🤖消息到钉钉群"
lane :send_dingding_msg do |options|
version = get_version_number(target: SCHEME)
text = "🚀🚀🚀测试包v#{version} Release环境打包更新啦,下载地址:https://www.pgyer.com/xxx ,请查收~ "
ding_talk_msg_push(token:dingding_token, text:text, at_all: true)
end发送更新日志到钉钉群
1
2
3
4
5
6# 打包之前准备好更新内容 log.txt 存放在fastlane同一目录层级
desc "获取更新日志并发送至钉钉机器人🤖"
lane :send_log_to_dingding do |options|
log_text = File.new("../log.txt", "r:utf-8").sysread(2000) #读取文本2000字
ding_talk_msg_push(token:dingding_token, text:log_text, at_all: true)
end可能用到的插件,在
Pluginfile
中添加1
2
3gem 'fastlane-plugin-pgyer'
gem 'fastlane-plugin-versioning'
gem 'fastlane-plugin-ding_talk_msg_push'