Skip to content

Commit a008597

Browse files
tweak json parsing
1 parent a6fdd16 commit a008597

3 files changed

Lines changed: 43 additions & 21 deletions

File tree

dist/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58474,22 +58474,28 @@ async function GetProjectDetails(credential, xcodeVersion) {
5847458474
silent: !core.isDebug()
5847558475
});
5847658476
destinationOutput = destinationOutput.replace(/Available destinations for the ".*" scheme:\n/, '');
58477-
const destinations = JSON.parse(destinationOutput);
58478-
core.info(`Available destinations: ${JSON.stringify(destinations, null, 2)}`);
58477+
let lines = destinationOutput.split('\n').filter(line => line.trim() !== '');
58478+
if (lines.length === 0) {
58479+
throw new Error(`No available destinations found for the project! Output: ${destinationOutput}`);
58480+
}
58481+
const destinations = [];
58482+
for (const line of lines) {
58483+
try {
58484+
const destination = JSON.parse(line);
58485+
destinations.push(destination);
58486+
}
58487+
catch (error) {
58488+
core.warning(`Failed to parse destination line: ${line}`);
58489+
}
58490+
}
5847958491
if (destinations.length === 0) {
5848058492
throw new Error(`No available destinations found for the project!\n${destinationOutput}`);
5848158493
}
58482-
const nameMatch = 'Any visionOS Simulator Device';
58483-
const matchedDestinations = destinations.filter((d) => d.name.includes(nameMatch));
58484-
if (matchedDestinations.length > 0) {
58485-
core.info(`Using destination: ${matchedDestinations[0].name}`);
58486-
destination = `platform=${matchedDestinations[0].platform},id=${matchedDestinations[0].id},name=${matchedDestinations[0].name}`;
58487-
}
5848858494
if (!destination) {
5848958495
core.info('No specific destination set, using the first available destination.');
5849058496
for (const dest of destinations) {
5849158497
if (dest.platform === platform) {
58492-
destination = `platform=${dest.platform},id=${dest.id},name=${dest.name}`;
58498+
destination = Object.entries(dest).map(([key, value]) => `${key}=${value}`).join(',');
5849358499
break;
5849458500
}
5849558501
}

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: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,37 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
9797
},
9898
silent: !core.isDebug()
9999
});
100-
// strip any previous string before json, bc xcodebuild outputs some text before the json:
100+
// Example output:
101101
// Available destinations for the "Unity-VisionOS" scheme:
102102
// { platform:visionOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-xrsimulator:placeholder, name:Any visionOS Simulator Device }
103103
// { platform:visionOS Simulator, arch:arm64, id:F1C1B167-8C5B-4737-B6A7-CF51DB6D5B70, OS:2.4, name:Apple Vision Pro }
104104
destinationOutput = destinationOutput.replace(/Available destinations for the ".*" scheme:\n/, '');
105-
const destinations = JSON.parse(destinationOutput);
106-
core.info(`Available destinations: ${JSON.stringify(destinations, null, 2)}`);
105+
let lines = destinationOutput.split('\n').filter(line => line.trim() !== '');
107106

108-
if (destinations.length === 0) {
109-
throw new Error(`No available destinations found for the project!\n${destinationOutput}`);
107+
if (lines.length === 0) {
108+
throw new Error(`No available destinations found for the project! Output: ${destinationOutput}`);
110109
}
111110

112-
const nameMatch = 'Any visionOS Simulator Device';
113-
const matchedDestinations = destinations.filter((d: any) => d.name.includes(nameMatch));
111+
const destinations: any[] = [];
112+
113+
for (const line of lines) {
114+
try {
115+
const destination = JSON.parse(line);
116+
destinations.push(destination);
117+
} catch (error) {
118+
core.warning(`Failed to parse destination line: ${line}`);
119+
}
120+
}
114121

115-
if (matchedDestinations.length > 0) {
116-
core.info(`Using destination: ${matchedDestinations[0].name}`);
117-
destination = `platform=${matchedDestinations[0].platform},id=${matchedDestinations[0].id},name=${matchedDestinations[0].name}`;
122+
if (destinations.length === 0) {
123+
throw new Error(`No available destinations found for the project!\n${destinationOutput}`);
118124
}
119125

120126
if (!destination) {
121127
core.info('No specific destination set, using the first available destination.');
122128
for (const dest of destinations) {
123129
if (dest.platform === platform) {
124-
destination = `platform=${dest.platform},id=${dest.id},name=${dest.name}`;
130+
destination = Object.entries(dest).map(([key, value]) => `${key}=${value}`).join(',');
125131
break;
126132
}
127133
}
@@ -131,30 +137,39 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
131137
core.debug(`Using destination: ${destination}`);
132138
const bundleId = await getBuildSettings(projectPath, scheme, platform, destination);
133139
core.info(`Bundle ID: ${bundleId}`);
140+
134141
if (!bundleId) {
135142
throw new Error('Unable to determine the bundle ID');
136143
}
144+
137145
let infoPlistPath = `${projectDirectory}/${projectName}/Info.plist`;
146+
138147
if (!fs.existsSync(infoPlistPath)) {
139148
infoPlistPath = `${projectDirectory}/Info.plist`;
140149
}
150+
141151
core.info(`Info.plist path: ${infoPlistPath}`);
142152
const infoPlistHandle = await fs.promises.open(infoPlistPath, fs.constants.O_RDONLY);
143153
let infoPlistContent: string;
154+
144155
try {
145156
infoPlistContent = await fs.promises.readFile(infoPlistHandle, 'utf8');
146157
} finally {
147158
await infoPlistHandle.close();
148159
}
160+
149161
const infoPlist = plist.parse(infoPlistContent) as any;
150162
let cFBundleShortVersionString: string = infoPlist['CFBundleShortVersionString'];
163+
151164
if (cFBundleShortVersionString) {
152165
const semverRegex = /^(?<major>\d+)\.(?<minor>\d+)\.(?<revision>\d+)/;
153166
const match = cFBundleShortVersionString.match(semverRegex);
167+
154168
if (match) {
155169
const { major, minor, revision } = match.groups as { [key: string]: string };
156170
cFBundleShortVersionString = `${major}.${minor}.${revision}`;
157171
infoPlist['CFBundleShortVersionString'] = cFBundleShortVersionString.toString();
172+
158173
try {
159174
core.info(`Updating Info.plist with CFBundleShortVersionString: ${cFBundleShortVersionString}`);
160175
await fs.promises.writeFile(infoPlistPath, plist.build(infoPlist));
@@ -165,6 +180,7 @@ export async function GetProjectDetails(credential: AppleCredential, xcodeVersio
165180
throw new Error(`Invalid CFBundleShortVersionString format: ${cFBundleShortVersionString}`);
166181
}
167182
}
183+
168184
core.info(`CFBundleShortVersionString: ${cFBundleShortVersionString}`);
169185
const cFBundleVersion = infoPlist['CFBundleVersion'] as string;
170186
core.info(`CFBundleVersion: ${cFBundleVersion}`);

0 commit comments

Comments
 (0)