@@ -20,6 +20,13 @@ import { SemVer } from 'semver';
2020const xcodebuild = '/usr/bin/xcodebuild' ;
2121const xcrun = '/usr/bin/xcrun' ;
2222const WORKSPACE = process . env . GITHUB_WORKSPACE || process . cwd ( ) ;
23+ const platforms = {
24+ 'iphoneos' : 'iOS' ,
25+ 'macosx' : 'macOS' ,
26+ 'appletvos' : 'tvOS' ,
27+ 'watchos' : 'watchOS' ,
28+ 'xros' : 'visionOS'
29+ } ;
2330
2431export async function GetProjectDetails ( credential : AppleCredential , xcodeVersion : SemVer ) : Promise < XcodeProject > {
2532 const projectPathInput = core . getInput ( 'project-path' ) || `${ WORKSPACE } /**/*.xcodeproj` ;
@@ -53,6 +60,7 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
5360 if ( ! platform ) {
5461 throw new Error ( 'Unable to determine the platform to build for.' ) ;
5562 }
63+ await getPlatformSdkVersion ( projectPath , scheme , platform ) ;
5664 core . info ( `Bundle ID: ${ bundleId } ` ) ;
5765 if ( ! bundleId ) {
5866 throw new Error ( 'Unable to determine the bundle ID' ) ;
@@ -121,31 +129,46 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
121129
122130async function parseBuildSettings ( projectPath : string ) : Promise < [ string , string ] > {
123131 const projectFilePath = `${ projectPath } /project.pbxproj` ;
132+ core . debug ( `.pbxproj file path: ${ projectFilePath } ` ) ;
124133 await fs . promises . access ( projectFilePath , fs . constants . R_OK ) ;
125134 const content = await fs . promises . readFile ( projectFilePath , 'utf8' ) ;
126- const platformName = core . getInput ( 'platform' ) || matchRegexPattern ( content , / \s + P L A T F O R M _ N A M E = (?< platformName > \w + ) / , 'platformName ' ) ;
135+ const platformName = core . getInput ( 'platform' ) || matchRegexPattern ( content , / \s + S D K _ R O O T = (?< platform > \w + ) / , 'platform ' ) ;
127136 if ( ! platformName ) {
128137 throw new Error ( 'Unable to determine the platform name from the build settings' ) ;
129138 }
130139 const bundleId = core . getInput ( 'bundle-id' ) || matchRegexPattern ( content , / \s + P R O D U C T _ B U N D L E _ I D E N T I F I E R = (?< bundleId > [ \w . - ] + ) / , 'bundleId' ) ;
131140 if ( ! bundleId || bundleId === 'NO' ) {
132141 throw new Error ( 'Unable to determine the bundle ID from the build settings' ) ;
133142 }
143+ return [ platforms [ platformName ] , bundleId ] ;
144+ }
145+
146+ async function getPlatformSdkVersion ( projectPath : string , scheme : string , platform : string ) {
147+ let buildSettingsOutput = '' ;
148+ const projectSettingsArgs = [
149+ 'build' ,
150+ '-project' , projectPath ,
151+ '-scheme' , scheme ,
152+ '-showBuildSettings'
153+ ] ;
154+ if ( ! core . isDebug ( ) ) {
155+ core . info ( `[command]${ xcodebuild } ${ projectSettingsArgs . join ( ' ' ) } ` ) ;
156+ }
157+ await exec ( xcodebuild , projectSettingsArgs , {
158+ listeners : {
159+ stdout : ( data : Buffer ) => {
160+ buildSettingsOutput += data . toString ( ) ;
161+ }
162+ } ,
163+ silent : ! core . isDebug ( )
164+ } ) ;
134165 let platformSdkVersion = core . getInput ( 'platform-sdk-version' ) || null ;
135166 if ( ! platformSdkVersion ) {
136- platformSdkVersion = matchRegexPattern ( content , / \s + S D K _ V E R S I O N = (?< sdkVersion > [ \d . ] + ) / , 'sdkVersion' ) || null ;
167+ platformSdkVersion = matchRegexPattern ( buildSettingsOutput , / \s + S D K _ V E R S I O N = (?< sdkVersion > [ \d . ] + ) / , 'sdkVersion' ) || null ;
137168 }
138- const platforms = {
139- 'iphoneos' : 'iOS' ,
140- 'macosx' : 'macOS' ,
141- 'appletvos' : 'tvOS' ,
142- 'watchos' : 'watchOS' ,
143- 'xros' : 'visionOS'
144- } ;
145- if ( platforms [ platformName ] !== 'macOS' ) {
146- await downloadPlatformSdkIfMissing ( platforms [ platformName ] , platformSdkVersion ) ;
169+ if ( platforms [ platform ] !== 'macOS' ) {
170+ await downloadPlatformSdkIfMissing ( platforms [ platform ] , platformSdkVersion ) ;
147171 }
148- return [ platforms [ platformName ] , bundleId ] ;
149172}
150173
151174function matchRegexPattern ( string : string , pattern : RegExp , group : string | null ) : string {
0 commit comments