Skip to content

Commit 2178992

Browse files
refactor how we check and install sdks
1 parent ecf72ab commit 2178992

File tree

4 files changed

+47
-68
lines changed

4 files changed

+47
-68
lines changed

dist/index.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58521,25 +58521,18 @@ async function GetOrSetXcodeVersion() {
5852158521
if (installedXcodeVersions.length === 0 || !installedXcodeVersions.includes(xcodeVersionString)) {
5852258522
throw new Error(`Xcode version ${xcodeVersionString} is not installed! You will need to install this is a step before this one.`);
5852358523
}
58524-
else {
58525-
core.info(`Selecting installed Xcode version ${xcodeVersionString}...`);
58526-
const selectExitCode = await (0, exec_1.exec)('xcodes', ['select', xcodeVersionString]);
58527-
if (selectExitCode !== 0) {
58528-
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
58529-
}
58530-
}
5853158524
}
5853258525
else {
5853358526
const nonBetaVersions = installedXcodeVersions.filter(v => !/Beta/i.test(v));
5853458527
if (nonBetaVersions.length === 0) {
5853558528
throw new Error('No Xcode versions installed!');
5853658529
}
5853758530
xcodeVersionString = nonBetaVersions[nonBetaVersions.length - 1];
58538-
core.info(`Selecting latest installed Xcode version ${xcodeVersionString}...`);
58539-
const selectExitCode = await (0, exec_1.exec)('xcodes', ['select', xcodeVersionString]);
58540-
if (selectExitCode !== 0) {
58541-
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
58542-
}
58531+
}
58532+
core.info(`Selecting latest installed Xcode version ${xcodeVersionString}...`);
58533+
const selectExitCode = await (0, exec_1.exec)('xcodes', ['select', xcodeVersionString]);
58534+
if (selectExitCode !== 0) {
58535+
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
5854358536
}
5854458537
}
5854558538
let xcodeVersionOutput = '';
@@ -58603,13 +58596,12 @@ async function GetProjectDetails(credential, xcodeVersion) {
5860358596
const platform = await getSupportedPlatform(projectPath);
5860458597
core.info(`Platform: ${platform}`);
5860558598
if (platform !== 'macOS') {
58606-
const platformInstalled = await isPlatformInstalled(platform);
58607-
if (!platformInstalled) {
58608-
await downloadPlatform(platform);
58609-
}
58610-
await checkSimulatorsAvailable(platform);
58599+
const platformInstalled = await isSdkPlatformInstalled(platform);
5861158600
const platformSdkVersion = await getPlatformSdkVersion(buildSettings);
58612-
await downloadPlatformSdkIfMissing(platform, platformSdkVersion);
58601+
const hasSimulators = await checkSimulatorsAvailable(platform);
58602+
if (!platformInstalled || !hasSimulators) {
58603+
await downloadPlatformAndSdk(platform, platformSdkVersion);
58604+
}
5861358605
}
5861458606
const configuration = core.getInput('configuration') || 'Release';
5861558607
core.info(`Configuration: ${configuration}`);
@@ -58781,10 +58773,7 @@ async function checkSimulatorsAvailable(platform) {
5878158773
const platformDevices = Object.keys(devices)
5878258774
.filter(key => key.toLowerCase().includes(platform.toLowerCase()))
5878358775
.flatMap(key => devices[key]);
58784-
if (platformDevices.length > 0) {
58785-
return;
58786-
}
58787-
await downloadPlatform(platform);
58776+
return platformDevices.length > 0;
5878858777
}
5878958778
async function getSupportedPlatform(projectPath) {
5879058779
const projectFilePath = `${projectPath}/project.pbxproj`;
@@ -58844,8 +58833,9 @@ async function getPlatformSdkVersion(buildSettingsOutput) {
5884458833
core.info(`Platform SDK version: ${platformSdkVersion}`);
5884558834
return platformSdkVersion;
5884658835
}
58847-
async function isPlatformInstalled(platform) {
58836+
async function isSdkPlatformInstalled(platform) {
5884858837
const output = await execXcodeBuild(['-showsdks']);
58838+
core.info(`SDKs available:\n${output}`);
5884958839
const sdkMap = {
5885058840
'iOS': 'iphoneos',
5885158841
'tvOS': 'appletvos',
@@ -58858,14 +58848,15 @@ async function isPlatformInstalled(platform) {
5885858848
}
5885958849
return output.includes(`-sdk ${sdkString}`);
5886058850
}
58861-
async function downloadPlatform(platform) {
58862-
await execXcodeBuild(['-downloadPlatform', platform]);
58863-
}
58864-
async function downloadPlatformSdkIfMissing(platform, version) {
58865-
await (0, exec_1.exec)('xcodes', ['runtimes']);
58866-
if (version) {
58867-
await (0, exec_1.exec)('xcodes', ['runtimes', 'install', `${platform} ${version}`]);
58851+
async function downloadPlatformAndSdk(platform, version) {
58852+
const downloadDir = `${process.env.RUNNER_TEMP}/xcodes/${platform}-${version}`;
58853+
await execXcodeBuild(['-downloadPlatform', platform, '-buildVersion', version, '-exportPath', downloadDir]);
58854+
const dmgPath = await (0, utilities_1.getFirstPathWithGlob)(`${downloadDir}/**/*.dmg`);
58855+
if (!dmgPath) {
58856+
throw new Error(`Failed to find downloaded .dmg for platform ${platform} version ${version}`);
5886858857
}
58858+
await fs.promises.access(dmgPath, fs.constants.X_OK);
58859+
await execXcodeBuild(['-importPlatform', dmgPath]);
5886958860
}
5887058861
async function getProjectScheme(projectPath) {
5887158862
let scheme = core.getInput('scheme');

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import core = require('@actions/core');
2-
import exec = require('@actions/exec');
32
import {
43
GetProjectDetails,
54
ArchiveXcodeProject,
@@ -12,7 +11,6 @@ import {
1211
ImportCredentials,
1312
RemoveCredentials
1413
} from './AppleCredential';
15-
import semver = require('semver');
1614

1715
const IS_POST = !!core.getState('isPost');
1816

src/xcode.ts

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ export async function GetOrSetXcodeVersion(): Promise<SemVer> {
6060
if (installedXcodeVersions.length === 0 || !xcodeVersionString.includes('latest')) {
6161
if (installedXcodeVersions.length === 0 || !installedXcodeVersions.includes(xcodeVersionString)) {
6262
throw new Error(`Xcode version ${xcodeVersionString} is not installed! You will need to install this is a step before this one.`);
63-
} else {
64-
core.info(`Selecting installed Xcode version ${xcodeVersionString}...`);
65-
const selectExitCode = await exec('xcodes', ['select', xcodeVersionString]);
66-
67-
if (selectExitCode !== 0) {
68-
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
69-
}
7063
}
7164
} else {
7265
// Exclude versions containing 'Beta' and select the latest version
@@ -77,12 +70,13 @@ export async function GetOrSetXcodeVersion(): Promise<SemVer> {
7770
}
7871

7972
xcodeVersionString = nonBetaVersions[nonBetaVersions.length - 1];
80-
core.info(`Selecting latest installed Xcode version ${xcodeVersionString}...`);
81-
const selectExitCode = await exec('xcodes', ['select', xcodeVersionString]);
73+
}
8274

83-
if (selectExitCode !== 0) {
84-
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
85-
}
75+
core.info(`Selecting latest installed Xcode version ${xcodeVersionString}...`);
76+
const selectExitCode = await exec('xcodes', ['select', xcodeVersionString]);
77+
78+
if (selectExitCode !== 0) {
79+
throw new Error(`Failed to select Xcode version ${xcodeVersionString}!`);
8680
}
8781
}
8882

@@ -160,15 +154,13 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
160154
core.info(`Platform: ${platform}`);
161155

162156
if (platform !== 'macOS') {
163-
const platformInstalled = await isPlatformInstalled(platform);
157+
const platformInstalled = await isSdkPlatformInstalled(platform);
158+
const platformSdkVersion = await getPlatformSdkVersion(buildSettings);
159+
const hasSimulators = await checkSimulatorsAvailable(platform);
164160

165-
if (!platformInstalled) {
166-
await downloadPlatform(platform);
161+
if (!platformInstalled || !hasSimulators) {
162+
await downloadPlatformAndSdk(platform, platformSdkVersion);
167163
}
168-
169-
await checkSimulatorsAvailable(platform);
170-
const platformSdkVersion = await getPlatformSdkVersion(buildSettings);
171-
await downloadPlatformSdkIfMissing(platform, platformSdkVersion);
172164
}
173165

174166
const configuration = core.getInput('configuration') || 'Release';
@@ -355,7 +347,7 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
355347
return projectRef;
356348
}
357349

358-
async function checkSimulatorsAvailable(platform: string): Promise<void> {
350+
async function checkSimulatorsAvailable(platform: string): Promise<Boolean> {
359351
const destinationArgs = ['simctl', 'list', 'devices', '--json'];
360352

361353
if (!core.isDebug()) {
@@ -378,11 +370,7 @@ async function checkSimulatorsAvailable(platform: string): Promise<void> {
378370
.filter(key => key.toLowerCase().includes(platform.toLowerCase()))
379371
.flatMap(key => devices[key]);
380372

381-
if (platformDevices.length > 0) {
382-
return;
383-
}
384-
385-
await downloadPlatform(platform);
373+
return platformDevices.length > 0;
386374
}
387375

388376
async function getSupportedPlatform(projectPath: string): Promise<string> {
@@ -459,10 +447,12 @@ async function getPlatformSdkVersion(buildSettingsOutput: string): Promise<strin
459447
return platformSdkVersion;
460448
}
461449

462-
async function isPlatformInstalled(platform: string): Promise<boolean> {
450+
async function isSdkPlatformInstalled(platform: string): Promise<boolean> {
463451
// Check if the platform SDK is available using xcodebuild -showsdks
464452
const output = await execXcodeBuild(['-showsdks']);
465453

454+
core.info(`SDKs available:\n${output}`);
455+
466456
// Example output line: "iOS SDKs:\n\tiOS 17.0 -sdk iphoneos17.0"
467457
const sdkMap: Record<string, string> = {
468458
'iOS': 'iphoneos',
@@ -471,20 +461,20 @@ async function isPlatformInstalled(platform: string): Promise<boolean> {
471461
'visionOS': 'xros',
472462
};
473463
const sdkString = sdkMap[platform];
464+
474465
if (!sdkString) { return false; }
475466
return output.includes(`-sdk ${sdkString}`);
476467
}
477468

478-
async function downloadPlatform(platform: string) {
479-
await execXcodeBuild(['-downloadPlatform', platform]);
480-
}
481-
482-
async function downloadPlatformSdkIfMissing(platform: string, version: string | null) {
483-
await exec('xcodes', ['runtimes']);
484-
485-
if (version) {
486-
await exec('xcodes', ['runtimes', 'install', `${platform} ${version}`]);
469+
async function downloadPlatformAndSdk(platform: string, version: string): Promise<void> {
470+
const downloadDir = `${process.env.RUNNER_TEMP}/xcodes/${platform}-${version}`;
471+
await execXcodeBuild(['-downloadPlatform', platform, '-buildVersion', version, '-exportPath', downloadDir]);
472+
const dmgPath = await getFirstPathWithGlob(`${downloadDir}/**/*.dmg`);
473+
if (!dmgPath) {
474+
throw new Error(`Failed to find downloaded .dmg for platform ${platform} version ${version}`);
487475
}
476+
await fs.promises.access(dmgPath, fs.constants.X_OK);
477+
await execXcodeBuild(['-importPlatform', dmgPath]);
488478
}
489479

490480
async function getProjectScheme(projectPath: string): Promise<string> {

0 commit comments

Comments
 (0)