@@ -57998,13 +57998,6 @@ const core = __nccwpck_require__(2186);
5799857998const xcodebuild = '/usr/bin/xcodebuild';
5799957999const xcrun = '/usr/bin/xcrun';
5800058000const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
58001- const platformMap = {
58002- 'iphoneos': 'iOS',
58003- 'macosx': 'macOS',
58004- 'appletvos': 'tvOS',
58005- 'watchos': 'watchOS',
58006- 'xros': 'visionOS'
58007- };
5800858001async function GetProjectDetails(credential, xcodeVersion) {
5800958002 const projectPathInput = core.getInput('project-path') || `${WORKSPACE}/**/*.xcodeproj`;
5801058003 core.debug(`Project path input: ${projectPathInput}`);
@@ -58032,18 +58025,19 @@ async function GetProjectDetails(credential, xcodeVersion) {
5803258025 core.info(`Project directory: ${projectDirectory}`);
5803358026 const projectName = path.basename(projectPath, '.xcodeproj');
5803458027 const scheme = await getProjectScheme(projectPath);
58035- const [ platform, bundleId] = await parseBuildSettings (projectPath);
58028+ const platform = await getSupportedPlatform (projectPath);
5803658029 core.info(`Platform: ${platform}`);
5803758030 if (!platform) {
5803858031 throw new Error('Unable to determine the platform to build for.');
5803958032 }
58033+ await checkSimulatorsAvailable(platform);
58034+ const destination = core.getInput('destination') || `generic/platform=${platform}`;
58035+ core.debug(`Using destination: ${destination}`);
58036+ const bundleId = await getBuildSettings(projectPath, scheme, platform, destination);
5804058037 core.info(`Bundle ID: ${bundleId}`);
5804158038 if (!bundleId) {
5804258039 throw new Error('Unable to determine the bundle ID');
5804358040 }
58044- const destination = core.getInput('destination') || `generic/platform=${platform}`;
58045- core.debug(`Using destination: ${destination}`);
58046- await getPlatformSdkVersion(projectPath, scheme, platform, destination);
5804758041 let infoPlistPath = `${projectDirectory}/${projectName}/Info.plist`;
5804858042 if (!fs.existsSync(infoPlistPath)) {
5804958043 infoPlistPath = `${projectDirectory}/Info.plist`;
@@ -58098,7 +58092,41 @@ async function GetProjectDetails(credential, xcodeVersion) {
5809858092 core.info(`----- Info.plist content: -----\n${infoPlistContent}\n-----------------------------------`);
5809958093 return projectRef;
5810058094}
58101- async function parseBuildSettings(projectPath) {
58095+ async function checkSimulatorsAvailable(platform) {
58096+ const destinationArgs = [
58097+ 'simctl',
58098+ 'list',
58099+ platform,
58100+ '--json'
58101+ ];
58102+ let output = '';
58103+ if (!core.isDebug()) {
58104+ core.info(`[command]${xcrun} ${destinationArgs.join(' ')}`);
58105+ }
58106+ await (0, exec_1.exec)(xcrun, destinationArgs, {
58107+ listeners: {
58108+ stdout: (data) => {
58109+ output += data.toString();
58110+ }
58111+ },
58112+ silent: !core.isDebug()
58113+ });
58114+ const response = JSON.parse(output);
58115+ const devices = response.devices;
58116+ if (devices.length > 0) {
58117+ return;
58118+ }
58119+ const simulators = response.simulators;
58120+ if (simulators.length > 0) {
58121+ return;
58122+ }
58123+ const availableDestinations = response.availableDestinations;
58124+ if (availableDestinations.length > 0) {
58125+ return;
58126+ }
58127+ await (0, exec_1.exec)(xcodebuild, ['-downloadPlatform', platform]);
58128+ }
58129+ async function getSupportedPlatform(projectPath) {
5810258130 const projectFilePath = `${projectPath}/project.pbxproj`;
5810358131 core.debug(`.pbxproj file path: ${projectFilePath}`);
5810458132 await fs.promises.access(projectFilePath, fs.constants.R_OK);
@@ -58107,14 +58135,16 @@ async function parseBuildSettings(projectPath) {
5810758135 if (!platform) {
5810858136 throw new Error('Unable to determine the platform name from the build settings');
5810958137 }
58110- const bundleId = core.getInput('bundle-id') || matchRegexPattern(content, /\s+PRODUCT_BUNDLE_IDENTIFIER = (?<bundleId>[\w.-]+)/, 'bundleId');
58111- if (!bundleId || bundleId === 'NO') {
58112- throw new Error('Unable to determine the bundle ID from the build settings');
58113- }
58114- return [platformMap[platform], bundleId];
58138+ const platformMap = {
58139+ 'iphoneos': 'iOS',
58140+ 'macosx': 'macOS',
58141+ 'appletvos': 'tvOS',
58142+ 'watchos': 'watchOS',
58143+ 'xros': 'visionOS'
58144+ };
58145+ return platformMap[platform];
5811558146}
58116- async function getPlatformSdkVersion(projectPath, scheme, platform, destination) {
58117- await (0, exec_1.exec)(xcodebuild, ['-downloadPlatform', platform]);
58147+ async function getBuildSettings(projectPath, scheme, platform, destination) {
5811858148 let buildSettingsOutput = '';
5811958149 const projectSettingsArgs = [
5812058150 'build',
@@ -58141,6 +58171,11 @@ async function getPlatformSdkVersion(projectPath, scheme, platform, destination)
5814158171 if (platform !== 'macOS') {
5814258172 await downloadPlatformSdkIfMissing(platform, platformSdkVersion);
5814358173 }
58174+ const bundleId = core.getInput('bundle-id') || matchRegexPattern(buildSettingsOutput, /\s+PRODUCT_BUNDLE_IDENTIFIER = (?<bundleId>[\w.-]+)/, 'bundleId');
58175+ if (!bundleId || bundleId === 'NO') {
58176+ throw new Error('Unable to determine the bundle ID from the build settings');
58177+ }
58178+ return bundleId;
5814458179}
5814558180function matchRegexPattern(string, pattern, group) {
5814658181 var _a;
0 commit comments