-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsetup-xcode.ts
55 lines (46 loc) · 1.89 KB
/
setup-xcode.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
import * as core from "@actions/core";
import { XcodeSelector } from "./xcode-selector";
import { getXcodeVersionFromDotFile } from "./xcode-version-file";
const run = (): void => {
try {
if (process.platform !== "darwin") {
throw new Error(
`This task is intended only for macOS platform. It can't be run on '${process.platform}' platform`
);
}
const defaultVersionSpec = "latest";
const versionSpec = (() => {
const inputValue = core.getInput("xcode-version", { required: false });
if (inputValue !== "") {
return inputValue;
} else {
return getXcodeVersionFromDotFile(process.env) ?? defaultVersionSpec;
}
})();
core.info(`Switching Xcode to version '${versionSpec}'...`);
const selector = new XcodeSelector();
if (core.isDebug()) {
core.startGroup("Available Xcode versions:");
core.debug(JSON.stringify(selector.getAllVersions(), null, 2));
core.endGroup();
}
const targetVersion = selector.findVersion(versionSpec);
if (!targetVersion) {
console.log("Available versions:");
console.table(selector.getAllVersions());
throw new Error(
`Could not find Xcode version that satisfied version spec: '${versionSpec}'`
);
}
core.debug(
`Xcode ${targetVersion.version} (${targetVersion.buildNumber}) (${targetVersion.path}) will be set`
);
selector.setVersion(targetVersion);
core.info(`Xcode is set to ${targetVersion.version} (${targetVersion.buildNumber})`);
core.setOutput("version", targetVersion.version);
core.setOutput("path", targetVersion.path);
} catch (error: unknown) {
core.setFailed((error as Error).message);
}
};
run();