-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathxcode-utils.ts
80 lines (68 loc) · 2.86 KB
/
xcode-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as path from "path";
import * as fs from "fs";
import * as core from "@actions/core";
import * as plist from "plist";
import * as semver from "semver";
export type XcodeVersionReleaseType = "GM" | "Beta" | "Unknown";
export interface XcodeVersion {
version: string;
buildNumber: string;
path: string;
releaseType: XcodeVersionReleaseType;
stable: boolean;
}
export const parsePlistFile = (plistPath: string): plist.PlistObject | null => {
if (!fs.existsSync(plistPath)) {
core.debug(`Unable to open plist file. File doesn't exist on path '${plistPath}'`);
return null;
}
const plistRawContent = fs.readFileSync(plistPath, "utf8");
return plist.parse(plistRawContent) as plist.PlistObject;
};
export const getInstalledXcodeApps = (): string[] => {
const applicationsDirectory = "/Applications";
const xcodeAppFilenameRegex = /^Xcode.*\.app$/;
const allApplicationsChildItems = fs.readdirSync(applicationsDirectory, {
encoding: "utf8",
withFileTypes: true,
});
const allApplicationsRealItems = allApplicationsChildItems.filter(
child => !child.isSymbolicLink() && child.isDirectory()
);
const xcodeAppsItems = allApplicationsRealItems.filter(app =>
xcodeAppFilenameRegex.test(app.name)
);
return xcodeAppsItems.map(child => path.join(applicationsDirectory, child.name));
};
export const getXcodeReleaseType = (xcodeRootPath: string): XcodeVersionReleaseType => {
const licenseInfo = parsePlistFile(
path.join(xcodeRootPath, "Contents", "Resources", "LicenseInfo.plist")
);
const licenseType = licenseInfo?.licenseType?.toString()?.toLowerCase();
if (!licenseType) {
core.debug("Unable to determine Xcode version type based on license plist");
core.debug("Xcode License plist doesn't contain 'licenseType' property");
return "Unknown";
}
return licenseType.includes("beta") ? "Beta" : "GM";
};
export const getXcodeVersionInfo = (xcodeRootPath: string): XcodeVersion | null => {
const versionInfo = parsePlistFile(path.join(xcodeRootPath, "Contents", "version.plist"));
const xcodeVersion = semver.coerce(versionInfo?.CFBundleShortVersionString?.toString());
const xcodeBuildNumber = versionInfo?.ProductBuildVersion?.toString();
if (!xcodeVersion || !semver.valid(xcodeVersion)) {
core.debug(`Unable to retrieve Xcode version info on path '${xcodeRootPath}'`);
return null;
}
const releaseType = getXcodeReleaseType(xcodeRootPath);
return {
version: xcodeVersion.version,
buildNumber: xcodeBuildNumber,
releaseType: releaseType,
stable: releaseType === "GM",
path: xcodeRootPath,
} as XcodeVersion;
};
export const developerDirPath = (xcodeVersion: XcodeVersion): string => {
return path.join(xcodeVersion.path, "Contents", "Developer");
};