Skip to content

Commit 0800fda

Browse files
more refactoring
1 parent f2c3865 commit 0800fda

3 files changed

Lines changed: 70 additions & 25 deletions

File tree

dist/index.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57997,6 +57997,13 @@ const core = __nccwpck_require__(2186);
5799757997
const xcodebuild = '/usr/bin/xcodebuild';
5799857998
const xcrun = '/usr/bin/xcrun';
5799957999
const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
58000+
const platforms = {
58001+
'iphoneos': 'iOS',
58002+
'macosx': 'macOS',
58003+
'appletvos': 'tvOS',
58004+
'watchos': 'watchOS',
58005+
'xros': 'visionOS'
58006+
};
5800058007
async function GetProjectDetails(credential, xcodeVersion) {
5800158008
const projectPathInput = core.getInput('project-path') || `${WORKSPACE}/**/*.xcodeproj`;
5800258009
core.debug(`Project path input: ${projectPathInput}`);
@@ -58029,6 +58036,7 @@ async function GetProjectDetails(credential, xcodeVersion) {
5802958036
if (!platform) {
5803058037
throw new Error('Unable to determine the platform to build for.');
5803158038
}
58039+
await getPlatformSdkVersion(projectPath, scheme, platform);
5803258040
core.info(`Bundle ID: ${bundleId}`);
5803358041
if (!bundleId) {
5803458042
throw new Error('Unable to determine the bundle ID');
@@ -58089,31 +58097,45 @@ async function GetProjectDetails(credential, xcodeVersion) {
5808958097
}
5809058098
async function parseBuildSettings(projectPath) {
5809158099
const projectFilePath = `${projectPath}/project.pbxproj`;
58100+
core.debug(`.pbxproj file path: ${projectFilePath}`);
5809258101
await fs.promises.access(projectFilePath, fs.constants.R_OK);
5809358102
const content = await fs.promises.readFile(projectFilePath, 'utf8');
58094-
const platformName = core.getInput('platform') || matchRegexPattern(content, /\s+PLATFORM_NAME = (?<platformName>\w+)/, 'platformName');
58103+
const platformName = core.getInput('platform') || matchRegexPattern(content, /\s+SDK_ROOT = (?<platform>\w+)/, 'platform');
5809558104
if (!platformName) {
5809658105
throw new Error('Unable to determine the platform name from the build settings');
5809758106
}
5809858107
const bundleId = core.getInput('bundle-id') || matchRegexPattern(content, /\s+PRODUCT_BUNDLE_IDENTIFIER = (?<bundleId>[\w.-]+)/, 'bundleId');
5809958108
if (!bundleId || bundleId === 'NO') {
5810058109
throw new Error('Unable to determine the bundle ID from the build settings');
5810158110
}
58111+
return [platforms[platformName], bundleId];
58112+
}
58113+
async function getPlatformSdkVersion(projectPath, scheme, platform) {
58114+
let buildSettingsOutput = '';
58115+
const projectSettingsArgs = [
58116+
'build',
58117+
'-project', projectPath,
58118+
'-scheme', scheme,
58119+
'-showBuildSettings'
58120+
];
58121+
if (!core.isDebug()) {
58122+
core.info(`[command]${xcodebuild} ${projectSettingsArgs.join(' ')}`);
58123+
}
58124+
await (0, exec_1.exec)(xcodebuild, projectSettingsArgs, {
58125+
listeners: {
58126+
stdout: (data) => {
58127+
buildSettingsOutput += data.toString();
58128+
}
58129+
},
58130+
silent: !core.isDebug()
58131+
});
5810258132
let platformSdkVersion = core.getInput('platform-sdk-version') || null;
5810358133
if (!platformSdkVersion) {
58104-
platformSdkVersion = matchRegexPattern(content, /\s+SDK_VERSION = (?<sdkVersion>[\d.]+)/, 'sdkVersion') || null;
58134+
platformSdkVersion = matchRegexPattern(buildSettingsOutput, /\s+SDK_VERSION = (?<sdkVersion>[\d.]+)/, 'sdkVersion') || null;
5810558135
}
58106-
const platforms = {
58107-
'iphoneos': 'iOS',
58108-
'macosx': 'macOS',
58109-
'appletvos': 'tvOS',
58110-
'watchos': 'watchOS',
58111-
'xros': 'visionOS'
58112-
};
58113-
if (platforms[platformName] !== 'macOS') {
58114-
await downloadPlatformSdkIfMissing(platforms[platformName], platformSdkVersion);
58136+
if (platforms[platform] !== 'macOS') {
58137+
await downloadPlatformSdkIfMissing(platforms[platform], platformSdkVersion);
5811558138
}
58116-
return [platforms[platformName], bundleId];
5811758139
}
5811858140
function matchRegexPattern(string, pattern, group) {
5811958141
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: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ 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 platforms = {
24+
'iphoneos': 'iOS',
25+
'macosx': 'macOS',
26+
'appletvos': 'tvOS',
27+
'watchos': 'watchOS',
28+
'xros': 'visionOS'
29+
};
2330

2431
export 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

122130
async 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+PLATFORM_NAME = (?<platformName>\w+)/, 'platformName');
135+
const platformName = core.getInput('platform') || matchRegexPattern(content, /\s+SDK_ROOT = (?<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+PRODUCT_BUNDLE_IDENTIFIER = (?<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+SDK_VERSION = (?<sdkVersion>[\d.]+)/, 'sdkVersion') || null;
167+
platformSdkVersion = matchRegexPattern(buildSettingsOutput, /\s+SDK_VERSION = (?<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

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

0 commit comments

Comments
 (0)