@@ -51,6 +51,53 @@ platform :ios do
5151 end
5252 end
5353
54+ desc "Setup code signing for a given project, target, and signing type"
55+ desc "Parameters:"
56+ desc "- project_path: Path to the Xcode project"
57+ desc "- target: Target name to configure"
58+ desc "- type: 'development' or 'appstore'"
59+ desc "Bundle identifier will be automatically extracted from the target"
60+ lane :setup_code_signing do |options |
61+ UI . message ( "Setting up code signing..." )
62+ UI . message ( options . inspect )
63+ proj_path = options [ :project_path ]
64+ target = options [ :target ]
65+ type = options [ :type ]
66+
67+ UI . user_error! ( "project_path is required" ) unless proj_path
68+ UI . user_error! ( "target is required" ) unless target
69+ UI . user_error! ( "type is required (development or appstore)" ) unless type
70+ UI . user_error! ( "type must be 'development' or 'appstore'" ) unless [ "development" , "appstore" ] . include? ( type )
71+
72+ # Extract bundle identifier from the target's build settings
73+ begin
74+ build_settings_output = sh ( "xcodebuild -project '#{ proj_path } ' -target '#{ target } ' -showBuildSettings | grep 'PRODUCT_BUNDLE_IDENTIFIER'" , log : false )
75+ app_identifier = build_settings_output . split ( '=' ) . last . strip
76+ UI . user_error! ( "Could not extract PRODUCT_BUNDLE_IDENTIFIER from target #{ target } " ) if app_identifier . empty?
77+ UI . message ( "Extracted app_identifier: #{ app_identifier } " )
78+ rescue => e
79+ UI . user_error! ( "Failed to extract bundle identifier from target #{ target } : #{ e . message } " )
80+ end
81+
82+ api_key_if_needed
83+ setup_circle_ci
84+
85+ # Sync code signing with the extracted app identifier
86+ sync_code_signing ( type : type , app_identifier : app_identifier , readonly : true )
87+
88+ # Update code signing settings
89+ update_code_signing_settings (
90+ use_automatic_signing : false ,
91+ path : proj_path ,
92+ team_id : "GJZR2MEM28" , # Developer Portal Team ID
93+ profile_name : lane_context [ SharedValues ::MATCH_PROVISIONING_PROFILE_MAPPING ] [ app_identifier ] ,
94+ targets : [ target ] ,
95+ code_sign_identity : "Apple Development: Created via API" ,
96+ )
97+
98+ UI . success ( "Code signing setup complete for #{ target } with #{ type } signing" )
99+ end
100+
54101 lane :build_examples_tests do
55102 api_key_if_needed
56103 setup_circle_ci
0 commit comments