-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup-xamarin.ts
71 lines (59 loc) · 2.81 KB
/
setup-xamarin.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
import * as core from "@actions/core";
import { MonoToolSelector } from "./mono-selector";
import { XamarinIosToolSelector } from "./xamarin-ios-selector";
import { XamarinMacToolSelector } from "./xamarin-mac-selector";
import { XamarinAndroidToolSelector } from "./xamarin-android-selector";
import { EOL } from "os";
import { VersionUtils } from "./version-utils";
import { ToolSelector } from "./tool-selector";
import { XcodeSelector } from "./xcode-selector";
let showVersionMajorMinorWarning = false;
const invokeSelector = (variableName: string, toolSelector: { new (): ToolSelector }): void => {
const versionSpec = core.getInput(variableName, { required: false });
if (!versionSpec) {
return;
}
const selector = new toolSelector();
if (!VersionUtils.isLatestVersionKeyword(versionSpec) && !VersionUtils.isValidVersion(versionSpec)) {
throw new Error(`Value '${versionSpec}' is not valid version for ${selector.toolName}`);
}
core.info(`Switching ${selector.toolName} to version '${versionSpec}'...`);
const targetVersion = selector.findVersion(versionSpec);
if (!targetVersion) {
throw new Error(
[
`Could not find ${selector.toolName} version that satisfied version spec: ${versionSpec}`,
"Available versions:",
...selector.getAllVersions().map(ver => `- ${ver}`)
].join(EOL)
);
}
core.debug(`${selector.toolName} ${targetVersion} will be set`);
selector.setVersion(targetVersion);
core.info(`${selector.toolName} is set to '${targetVersion}'`);
showVersionMajorMinorWarning = showVersionMajorMinorWarning || VersionUtils.countVersionLength(versionSpec) > 2;
};
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`);
}
invokeSelector("mono-version", MonoToolSelector);
invokeSelector("xamarin-ios-version", XamarinIosToolSelector);
invokeSelector("xamarin-mac-version", XamarinMacToolSelector);
invokeSelector("xamarin-android-version", XamarinAndroidToolSelector);
invokeSelector("xcode-version", XcodeSelector);
if (showVersionMajorMinorWarning) {
core.warning(
[
"It is recommended to specify only major and minor versions of tool (like '13' or '13.2').",
"Hosted VMs contain the latest patch & build version for each major & minor pair.",
"It means that version '13.2.1.4' can be replaced by '13.2.2.0' without any notice and your pipeline will start failing."
].join(" ")
);
}
} catch (error) {
core.setFailed(error.message);
}
};
run();