11require "shellwords"
2+ require "fileutils"
23
34default_platform ( :ios )
45
@@ -12,6 +13,34 @@ def app_store_api_key!
1213 )
1314end
1415
16+ def write_export_options_plist ( path :, team_id :)
17+ File . write (
18+ path ,
19+ <<~PLIST
20+ <?xml version="1.0" encoding="UTF-8"?>
21+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
22+ <plist version="1.0">
23+ <dict>
24+ <key>destination</key>
25+ <string>export</string>
26+ <key>manageAppVersionAndBuildNumber</key>
27+ <false/>
28+ <key>method</key>
29+ <string>app-store-connect</string>
30+ <key>signingStyle</key>
31+ <string>automatic</string>
32+ <key>stripSwiftSymbols</key>
33+ <true/>
34+ <key>teamID</key>
35+ <string>#{ team_id } </string>
36+ <key>uploadSymbols</key>
37+ <true/>
38+ </dict>
39+ </plist>
40+ PLIST
41+ )
42+ end
43+
1544platform :ios do
1645 desc "Build a signed App Store IPA"
1746 lane :build_release do |options |
@@ -24,6 +53,15 @@ platform :ios do
2453 UI . user_error! ( "IOS_PROFILE_NAME is required" ) if profile_name . to_s . empty?
2554 UI . user_error! ( "IOS_TEAM_ID is required" ) if team_id . to_s . empty?
2655
56+ output_dir = "App/output"
57+ archive_path = File . join ( output_dir , "App.xcarchive" )
58+ export_path = File . join ( output_dir , "export" )
59+ export_options_path = File . join ( output_dir , "ExportOptions.plist" )
60+
61+ FileUtils . rm_rf ( export_path )
62+ FileUtils . mkdir_p ( output_dir )
63+ write_export_options_plist ( path : export_options_path , team_id : team_id )
64+
2765 update_code_signing_settings (
2866 path : "App/App.xcodeproj" ,
2967 use_automatic_signing : false ,
@@ -34,26 +72,34 @@ platform :ios do
3472 code_sign_identity : sign_identity
3573 )
3674
37- build_ios_app (
38- workspace : "App/App.xcworkspace" ,
39- scheme : "App" ,
40- configuration : "Release" ,
41- clean : true ,
42- skip_profile_detection : true ,
43- archive_path : "App/output/App.xcarchive" ,
44- output_directory : "App/output" ,
45- output_name : output_name ,
46- export_method : "app-store" ,
47- xcargs : [
48- "DEVELOPMENT_TEAM=#{ Shellwords . escape ( team_id ) } " ,
49- "PRODUCT_BUNDLE_IDENTIFIER=#{ Shellwords . escape ( bundle_id ) } " ,
50- ] . join ( " " ) ,
51- export_options : {
52- signingStyle : "automatic" ,
53- teamID : team_id ,
54- manageAppVersionAndBuildNumber : false ,
55- }
75+ sh (
76+ [
77+ "xcodebuild" ,
78+ "-workspace" , "App/App.xcworkspace" ,
79+ "-scheme" , "App" ,
80+ "-configuration" , "Release" ,
81+ "-archivePath" , archive_path ,
82+ "archive" ,
83+ "DEVELOPMENT_TEAM=#{ team_id } " ,
84+ "PRODUCT_BUNDLE_IDENTIFIER=#{ bundle_id } " ,
85+ ] . shelljoin
5686 )
87+
88+ sh (
89+ [
90+ "xcodebuild" ,
91+ "-exportArchive" ,
92+ "-archivePath" , archive_path ,
93+ "-exportPath" , export_path ,
94+ "-exportOptionsPlist" , export_options_path ,
95+ ] . shelljoin
96+ )
97+
98+ ipa_path = Dir [ File . join ( export_path , "*.ipa" ) ] . first
99+ UI . user_error! ( "No IPA was produced in #{ export_path } " ) if ipa_path . to_s . empty?
100+
101+ final_ipa_path = File . join ( output_dir , output_name )
102+ FileUtils . cp ( ipa_path , final_ipa_path )
57103 end
58104
59105 desc "Upload an existing IPA to TestFlight"
0 commit comments