接上篇: iOS(Swift) fastlane集成,分发蒲公英,fir
fastlane 文件源码
default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
# puts "beta测试"
increment_build_number(xcodeproj: "quick.xcodeproj")
puts "************打包开始************"
build_app(
clean: false,
scheme: "quick",
workspace: "quick.xcworkspace",
scheme: "quick",
output_directory: "fastlane/build/test/",
output_name: "quick.ipa",
xcargs: [
"-allowProvisioningUpdates"
],
configuration: "Release",#打包方式1:Debug 2:Test 3:PreRelease 4:Release"
silent: false,#在构建时隐藏终端不必要输出的信息
export_method: "app-store", # app-store, ad-hoc, package, enterprise, development, developer-id
# codesigning_identity: "Apple Distribution: Chongqing Taoqu Network Technology Co., Ltd. (FK4PHF763J)",
)
# notification(app_icon:"../quick/Assets/Assets.xcassets/AppIcon.appiconset",title:"发包中",subtitle: "打包成功,已导出安装包>>>>>>>>", message: "准备发布中....")
puts "************打包结束************"
puts "************上传testflight开始************"
api_key = app_store_connect_api_key(
key_id: "VF**********66",
issuer_id: "91be5**********6ae18152",
key_filepath: "cer/AuthKey_VF2FK5D566.p8",
duration: 1200, # optional (maximum 1200)
in_house: false # optional but may be required if using match/sigh
)
upload_to_testflight(
api_key: api_key,
skip_waiting_for_build_processing: true,
# username: "[email protected]",
# app_identifier: "com.sxx.xxx",
ipa: "fastlane/build/test/quick.ipa",
skip_submission:true
)
# notification(app_icon:"icon.png",title:"LoanManager",subtitle: "IPA上传成功", message: "自动打包完成!")
puts "************上传testflight结束************"
puts "************发送钉钉消息开始************"
ipa_path = ENV['FASTLANE_IPA_OUTPUT_PATH']
version_number = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleShortVersionString")#获取 info 属性
build_number = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleVersion")
branch_name = git_branch
commit = last_git_commit#提交
commit_hash = commit[:abbreviated_commit_hash]#提交 hash
commit_author = commit[:author]#作者
commit_info = "> last commit hash: #{commit_hash}, author: #{commit_author}"#提交信息
build_message = "quick_TestFlight(#{branch_name}) \n版本号: #{version_number}.#{build_number}\n testflight 已更新"
sh("ruby ./dingSuccess.rb '#{build_message}'")
puts "************发送钉钉消息结束************"
# if a == "222"
# end
end
after_all do |lane|
end
error do |lane, exception|
puts "操作失败了"
end
end
命令参数说明
其实也没啥好说的,稍微要注意下的是,脚本执行完后,会向 ENV 填充参数,比如ipa_path = ENV['FASTLANE_IPA_OUTPUT_PATH']
,需要的信息可以从 action 列表中获取,git 操作的信息也可以获取到,如果你是 ci/cd 操作的话,甚至应该做到git pull,increment_build_number增加构建号,pod update,git push,git checkout .等等操作,由于我是本地执行,省去了这些步骤,其实没啥好说的,一点点测试 API 就能慢慢做完,这东西除了基本的知识的话,剩下的就是耐心了.
build_app
- clean: 是否执行 cmd+shift+k
- sheme: 分享,openURL所用的 scheme
- workspace 基本都用这个,项目 workspace 名
- output_directory: 文件输出目录,相对路径相对于 root 目录
- output_name: build 打包 ipa 文件名
- xcargs->-allowProvisioningUpdates
问题解决出处
加上这个参数,帮助 fastlane 访问钥匙串,期间会多次弹出钥匙串密码弹窗,同意即可
upload_to_testflight
- api_key
- app_store_connect_api_key
- key_id: 后面设置 key 中有提到
- issuer_id: 设置密钥时同页面能看到该 id
- key_filepath: 设置密钥时能下载且只能下载一次
- skip_waiting_for_build_processing: 如果设置为true,distribute_external选项将不起作用,并且不会向测试人员分发任何构建。(如果您在CI上使用此操作,并且必须为CI计划中的“使用分钟数”付费,则可能需要使用此选项)。如果设置为true并提供了变更日志,它将部分等待生成出现在AppStore Connect上,以便可以设置变更日志,并跳过其余的处理步骤
- ipa: 要上传的 ipa 路径,可以用ENV['FASTLANE_IPA_OUTPUT_PATH']获取
- skip_submission: 跳过pilot的分发操作,只上传ipa文件
部分参数,均可灵活配置,灵活程度甚至大于手动上传(我目前知道的 tf 上传没有什么skip_waiting_for_build_processing选项)
- app_store_connect_api_key
成功 dingding 脚本
require "dingbot"
DingBot.endpoint='https://oapi.dingtalk.com/robot/send'
DingBot.access_token = 'd4d823d55b0e0d******************564e0189f7bff6b54ad63f51'
DingBot.secret = "SEC23eb83c18d5fbeb******************1acfbaec0427c96" # sign secret
def send_text
msg = ARGV[0] || "tf 更新,无更新信息"
message = DingBot::Message::Text.new(
msg,
['18******************012'],
false
)
DingBot.send_msg(message)
end
send_text
- 输入 appleId
- 上报出错 需要app-specific password
申请 key
问题1: 描述资源文件冲突
error: QuickKit has conflicting provisioning settings. QuickKit is automatically signed, but code signing identity Apple Distribution: Chongqing Taoqu Network Technology Co., Ltd. (FK4PHF763J) has been manually specified. Set the code signing identity value to "Apple Development" in the build settings editor, or switch to manual signing in the Signing & Capabilities editor. (in target 'QuickKit' from project 'quick')
- provisioning冲突,尝试注释codesigning_identity后打包成功,中间需要输入钥匙串的登录许可,输入密码,点始终允许即可.
问题2: 出口合规证明
- 修改 info.plist,添加
ITSAppUsesNonExemptEncryption
- 重新打包上传即可
- 结果展示
确实节省了非常多时间有需要的童鞋可以试试
感谢
iOS+Fastlane自动打包发布到TestFlight