@@ -119,7 +119,25 @@ platform :ios do
119119 # Re-sign with the Apple Distribution certificate before creating IPA.
120120 # exportArchive normally does this, but we bypass it for Xcode 26 compat.
121121 exported_app = File . join ( payload_dir , File . basename ( app_path ) )
122- sign_identity = "iPhone Distribution"
122+
123+ # Ensure the temp keychain is in the search list so codesign can find the cert
124+ keychain_path = File . expand_path ( "~/Library/Keychains/#{ keychain_name } -db" )
125+ existing = `security list-keychains -d user` . scan ( /"(.+?)"/ ) . flatten
126+ unless existing . any? { |k | k . include? ( keychain_name ) }
127+ sh ( "security list-keychains -d user -s #{ existing . map { |k | %Q["#{ k } "] } . join ( ' ' ) } '#{ keychain_path } '" )
128+ end
129+ sh ( "security set-keychain-settings '#{ keychain_path } '" )
130+ sh ( "security unlock-keychain -p '#{ keychain_password } ' '#{ keychain_path } '" )
131+
132+ # Find the distribution signing identity (SHA-1) from the temp keychain.
133+ # Match installs "Apple Distribution" (modern) or "iPhone Distribution" (legacy).
134+ identity_output = `security find-identity -v -p codesigning '#{ keychain_path } '`
135+ UI . message ( "Available signing identities:\n #{ identity_output } " )
136+ identity_match = identity_output . match ( /([0-9A-F]{40})\s +"(Apple Distribution|iPhone Distribution)[^"]*"/ )
137+ UI . user_error! ( "No distribution signing identity found in keychain '#{ keychain_name } '" ) unless identity_match
138+ sign_identity = identity_match [ 1 ] # Use SHA-1 hash — unambiguous
139+ UI . message ( "Using signing identity: #{ identity_match [ 2 ] } (#{ sign_identity } )" )
140+
123141 main_profile = ENV [ "PROVISIONING_PROFILE_SPECIFIER" ] ||
124142 "match AppStore #{ DEVELOPER_APP_IDENTIFIER } "
125143 ext_profile = "match AppStore #{ DEVELOPER_APP_EXTENSION_IDENTIFIER } "
@@ -145,7 +163,7 @@ platform :ios do
145163 frameworks_path = File . join ( exported_app , "Frameworks" )
146164 if File . directory? ( frameworks_path )
147165 Dir [ "#{ frameworks_path } /*.framework" , "#{ frameworks_path } /*.dylib" ] . each do |fw |
148- sh ( "codesign --force --sign '#{ sign_identity } ' --timestamp=none '#{ fw } '" )
166+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- timestamp=none '#{ fw } '" )
149167 end
150168 end
151169
@@ -158,23 +176,23 @@ platform :ios do
158176 appex_fw = File . join ( appex , "Frameworks" )
159177 if File . directory? ( appex_fw )
160178 Dir [ "#{ appex_fw } /*.framework" , "#{ appex_fw } /*.dylib" ] . each do |fw |
161- sh ( "codesign --force --sign '#{ sign_identity } ' --timestamp=none '#{ fw } '" )
179+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- timestamp=none '#{ fw } '" )
162180 end
163181 end
164182 entitlements_appex = File . join ( appex , "archived-expanded-entitlements.xcent" )
165183 if File . exist? ( entitlements_appex )
166- sh ( "codesign --force --sign '#{ sign_identity } ' --entitlements '#{ entitlements_appex } ' --timestamp=none '#{ appex } '" )
184+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- entitlements '#{ entitlements_appex } ' --timestamp=none '#{ appex } '" )
167185 else
168- sh ( "codesign --force --sign '#{ sign_identity } ' --timestamp=none '#{ appex } '" )
186+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- timestamp=none '#{ appex } '" )
169187 end
170188 end
171189
172190 # Re-sign the main app bundle
173191 entitlements_main = File . join ( exported_app , "archived-expanded-entitlements.xcent" )
174192 if File . exist? ( entitlements_main )
175- sh ( "codesign --force --sign '#{ sign_identity } ' --entitlements '#{ entitlements_main } ' --timestamp=none '#{ exported_app } '" )
193+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- entitlements '#{ entitlements_main } ' --timestamp=none '#{ exported_app } '" )
176194 else
177- sh ( "codesign --force --sign '#{ sign_identity } ' --timestamp=none '#{ exported_app } '" )
195+ sh ( "codesign --force --sign '#{ sign_identity } ' --keychain ' #{ keychain_path } ' -- timestamp=none '#{ exported_app } '" )
178196 end
179197
180198 ipa_output = File . join ( export_path , "Code.ipa" )
0 commit comments