打包腳本集成
- 定義好可配置項,方便修改
# 先定義好全局變量
SCHEME = "xxx"
WORKSPACE = "xxx.xcworkspace"
XCODEPROJ = "xxx.xcodeproj"
BundleId = "com.xxx.ooo"
dingding_token = "xxxxoooo" #電腦端釘釘建群群助手添加機器人webhook設置好獲取token即可 發消息得帶tag不然可能失敗
-
打包到Testflight
desc "打包到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
desc "部署到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分發包
cert #獲取證書 #驗證簽名 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()
-
上傳至蒲公英分發平台 (這個平時用的比較多)
private_lane :upload_ipa_to_pgyer do |options| pgyer( api_key: "xxxxx", user_key: "xxxxx", ipa: ".ipa/#{options[:scheme]}/#{options[:time]}/app.ipa" ) end
-
發送釘釘機器人消息
desc "發送機器人🤖消息到釘釘群" 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
-
發送更新日志到釘釘群
# 打包之前准備好更新內容 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
中添加gem 'fastlane-plugin-pgyer' gem 'fastlane-plugin-versioning' gem 'fastlane-plugin-ding_talk_msg_push'