Skip to content

Commit 88d46f3

Browse files
more refactoring
1 parent c0cab81 commit 88d46f3

3 files changed

Lines changed: 110 additions & 39 deletions

File tree

dist/index.js

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57998,13 +57998,6 @@ const core = __nccwpck_require__(2186);
5799857998
const xcodebuild = '/usr/bin/xcodebuild';
5799957999
const xcrun = '/usr/bin/xcrun';
5800058000
const 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-
};
5800858001
async 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
}
5814558180
function matchRegexPattern(string, pattern, group) {
5814658181
var _a;

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/xcode.ts

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ import { SemVer } from 'semver';
2020
const xcodebuild = '/usr/bin/xcodebuild';
2121
const xcrun = '/usr/bin/xcrun';
2222
const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
23-
const platformMap = {
24-
'iphoneos': 'iOS',
25-
'macosx': 'macOS',
26-
'appletvos': 'tvOS',
27-
'watchos': 'watchOS',
28-
'xros': 'visionOS'
29-
};
3023

3124
export async function GetProjectDetails(credential: AppleCredential, xcodeVersion: SemVer): Promise<XcodeProject> {
3225
const projectPathInput = core.getInput('project-path') || `${WORKSPACE}/**/*.xcodeproj`;
@@ -55,18 +48,19 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
5548
core.info(`Project directory: ${projectDirectory}`);
5649
const projectName = path.basename(projectPath, '.xcodeproj');
5750
const scheme = await getProjectScheme(projectPath);
58-
const [platform, bundleId] = await parseBuildSettings(projectPath);
51+
const platform = await getSupportedPlatform(projectPath);
5952
core.info(`Platform: ${platform}`);
6053
if (!platform) {
6154
throw new Error('Unable to determine the platform to build for.');
6255
}
56+
await checkSimulatorsAvailable(platform);
57+
const destination = core.getInput('destination') || `generic/platform=${platform}`;
58+
core.debug(`Using destination: ${destination}`);
59+
const bundleId = await getBuildSettings(projectPath, scheme, platform, destination);
6360
core.info(`Bundle ID: ${bundleId}`);
6461
if (!bundleId) {
6562
throw new Error('Unable to determine the bundle ID');
6663
}
67-
const destination = core.getInput('destination') || `generic/platform=${platform}`;
68-
core.debug(`Using destination: ${destination}`);
69-
await getPlatformSdkVersion(projectPath, scheme, platform, destination);
7064
let infoPlistPath = `${projectDirectory}/${projectName}/Info.plist`;
7165
if (!fs.existsSync(infoPlistPath)) {
7266
infoPlistPath = `${projectDirectory}/Info.plist`;
@@ -130,7 +124,42 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
130124
return projectRef;
131125
}
132126

133-
async function parseBuildSettings(projectPath: string): Promise<[string, string]> {
127+
async function checkSimulatorsAvailable(platform: string): Promise<void> {
128+
const destinationArgs = [
129+
'simctl',
130+
'list',
131+
platform,
132+
'--json'
133+
];
134+
let output = '';
135+
if (!core.isDebug()) {
136+
core.info(`[command]${xcrun} ${destinationArgs.join(' ')}`);
137+
}
138+
await exec(xcrun, destinationArgs, {
139+
listeners: {
140+
stdout: (data: Buffer) => {
141+
output += data.toString();
142+
}
143+
},
144+
silent: !core.isDebug()
145+
});
146+
const response = JSON.parse(output);
147+
const devices = response.devices as any[];
148+
if (devices.length > 0) {
149+
return;
150+
}
151+
const simulators = response.simulators as any[];
152+
if (simulators.length > 0) {
153+
return;
154+
}
155+
const availableDestinations = response.availableDestinations as any[];
156+
if (availableDestinations.length > 0) {
157+
return;
158+
}
159+
await exec(xcodebuild, ['-downloadPlatform', platform]);
160+
}
161+
162+
async function getSupportedPlatform(projectPath: string): Promise<string> {
134163
const projectFilePath = `${projectPath}/project.pbxproj`;
135164
core.debug(`.pbxproj file path: ${projectFilePath}`);
136165
await fs.promises.access(projectFilePath, fs.constants.R_OK);
@@ -139,15 +168,17 @@ async function parseBuildSettings(projectPath: string): Promise<[string, string]
139168
if (!platform) {
140169
throw new Error('Unable to determine the platform name from the build settings');
141170
}
142-
const bundleId = core.getInput('bundle-id') || matchRegexPattern(content, /\s+PRODUCT_BUNDLE_IDENTIFIER = (?<bundleId>[\w.-]+)/, 'bundleId');
143-
if (!bundleId || bundleId === 'NO') {
144-
throw new Error('Unable to determine the bundle ID from the build settings');
145-
}
146-
return [platformMap[platform], bundleId];
171+
const platformMap = {
172+
'iphoneos': 'iOS',
173+
'macosx': 'macOS',
174+
'appletvos': 'tvOS',
175+
'watchos': 'watchOS',
176+
'xros': 'visionOS'
177+
};
178+
return platformMap[platform];
147179
}
148180

149-
async function getPlatformSdkVersion(projectPath: string, scheme: string, platform: string, destination: string): Promise<void> {
150-
await exec(xcodebuild, ['-downloadPlatform', platform]);
181+
async function getBuildSettings(projectPath: string, scheme: string, platform: string, destination: string): Promise<string> {
151182
let buildSettingsOutput = '';
152183
const projectSettingsArgs = [
153184
'build',
@@ -174,6 +205,11 @@ async function getPlatformSdkVersion(projectPath: string, scheme: string, platfo
174205
if (platform !== 'macOS') {
175206
await downloadPlatformSdkIfMissing(platform, platformSdkVersion);
176207
}
208+
const bundleId = core.getInput('bundle-id') || matchRegexPattern(buildSettingsOutput, /\s+PRODUCT_BUNDLE_IDENTIFIER = (?<bundleId>[\w.-]+)/, 'bundleId');
209+
if (!bundleId || bundleId === 'NO') {
210+
throw new Error('Unable to determine the bundle ID from the build settings');
211+
}
212+
return bundleId;
177213
}
178214

179215
function matchRegexPattern(string: string, pattern: RegExp, group: string | null): string {

0 commit comments

Comments
 (0)