Skip to content

Commit f5ae481

Browse files
fix(fastlane): restrict CI keychain to GitHub Actions only
- Check GITHUB_ACTIONS env in addition to CI to avoid GUI prompts on dev machines - Set default_keychain: false to preserve user's login keychain - Add security set-key-partition-list call so codesign can access keys without prompts - Cleanup function now uses same guard conditions
1 parent 8b3dab5 commit f5ae481

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

fastlane/Fastfile

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,37 @@ def update_tauri_config_version
124124
end
125125

126126
# Setup temporary keychain for CI environments
127+
# Only runs on GitHub Actions (not local CI) to avoid GUI prompts on dev machines
127128
def setup_ci_keychain
128-
if ENV['CI']
129-
create_keychain(
130-
name: CI_KEYCHAIN_NAME,
131-
password: CI_KEYCHAIN_PASSWORD,
132-
default_keychain: true,
133-
unlock: true,
134-
timeout: 3600,
135-
lock_when_sleeps: false,
136-
add_to_search_list: true
137-
)
138-
end
129+
return unless ENV['CI'] && ENV['GITHUB_ACTIONS']
130+
131+
create_keychain(
132+
name: CI_KEYCHAIN_NAME,
133+
password: CI_KEYCHAIN_PASSWORD,
134+
default_keychain: false, # don't replace user's default keychain
135+
unlock: true,
136+
timeout: 3600,
137+
lock_when_sleeps: false,
138+
add_to_search_list: true
139+
)
140+
end
141+
142+
# Set partition list after match imports keys so codesign can access without GUI prompt
143+
def set_keychain_partition_list
144+
return unless ENV['CI'] && ENV['GITHUB_ACTIONS']
145+
146+
keychain_path = File.expand_path("~/Library/Keychains/#{CI_KEYCHAIN_NAME}-db")
147+
return unless File.exist?(keychain_path)
148+
149+
sh("security set-key-partition-list -S apple-tool:,apple: -s -k #{CI_KEYCHAIN_PASSWORD.shellescape} #{keychain_path.shellescape}", log: false)
139150
end
140151

141152
# Cleanup CI keychain
142153
def cleanup_ci_keychain
143-
if ENV['CI']
144-
delete_keychain(name: CI_KEYCHAIN_NAME) if File.exist?(File.expand_path("~/Library/Keychains/#{CI_KEYCHAIN_NAME}-db"))
145-
end
154+
return unless ENV['CI'] && ENV['GITHUB_ACTIONS']
155+
156+
keychain_path = File.expand_path("~/Library/Keychains/#{CI_KEYCHAIN_NAME}-db")
157+
delete_keychain(name: CI_KEYCHAIN_NAME) if File.exist?(keychain_path)
146158
end
147159

148160
platform :ios do
@@ -156,6 +168,7 @@ platform :ios do
156168
keychain_name: ENV['CI'] ? CI_KEYCHAIN_NAME : nil,
157169
keychain_password: ENV['CI'] ? CI_KEYCHAIN_PASSWORD : nil
158170
)
171+
set_keychain_partition_list
159172
end
160173

161174
desc "Build only (no upload) - for testing"
@@ -222,6 +235,7 @@ platform :ios do
222235
keychain_name: ENV['CI'] ? CI_KEYCHAIN_NAME : nil,
223236
keychain_password: ENV['CI'] ? CI_KEYCHAIN_PASSWORD : nil
224237
)
238+
set_keychain_partition_list
225239

226240
# Update tauri.conf.json with version and unique build number BEFORE init
227241
# This ensures Tauri uses the correct version when generating the iOS project
@@ -307,6 +321,7 @@ platform :ios do
307321
keychain_name: ENV['CI'] ? CI_KEYCHAIN_NAME : nil,
308322
keychain_password: ENV['CI'] ? CI_KEYCHAIN_PASSWORD : nil
309323
)
324+
set_keychain_partition_list
310325

311326
# Update tauri.conf.json with version and unique build number BEFORE init
312327
# This ensures Tauri uses the correct version when generating the iOS project

0 commit comments

Comments
 (0)