-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinstallTool.ts
68 lines (61 loc) · 2.19 KB
/
installTool.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
import { join } from "path"
import { endGroup, startGroup } from "@actions/core"
import { error } from "ci-log"
import { setupBrew } from "setup-brew"
import { getSuccessMessage, rcOptions } from "./options.js"
import { type ToolName, llvmTools, setups } from "./tool.js"
import type { InstallationInfo } from "./utils/setup/setupBin.js"
import { setupVCVarsall } from "./vcvarsall/vcvarsall.js"
import { getVersion } from "./versions/versions.js"
export const DEFAULT_TIMEOUT = 60 * 60 * 1000 // 60 minutes
export async function installTool(
tool: ToolName,
version: string,
osVersion: number[] | null,
arch: string,
setupCppDir: string,
successMessages: string[],
errorMessages: string[],
_timeout: number = DEFAULT_TIMEOUT, // TODO: pass to execa
) {
startGroup(`Installing ${tool} ${version}`)
try {
await installToolImpl(tool, version, osVersion, arch, setupCppDir, successMessages)
} catch (e) {
// push error message to the logger
error(e as string | Error)
if (e instanceof Error && e.stack !== undefined) {
error(e.stack)
}
errorMessages.push(`${tool} failed to install`)
}
endGroup()
}
async function installToolImpl(
tool: ToolName,
version: string,
osVersion: number[] | null,
arch: string,
setupCppDir: string,
successMessages: string[],
) {
const hasLLVM = llvmTools.includes(tool)
let installationInfo: InstallationInfo | undefined | void
if (tool === "vcvarsall") {
// eslint-disable-next-line no-await-in-loop
await setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
} else if (tool === "brew") {
// eslint-disable no-await-in-loop
installationInfo = await setupBrew({ rcOptions })
} else {
// the tool installation directory (for the functions that ue it)
const setupDir = join(setupCppDir, hasLLVM ? "llvm" : tool)
const setupVersion = getVersion(tool, version, osVersion)
// get the setup function
const setupFunction = setups[tool]
// eslint-disable no-await-in-loop
installationInfo = await setupFunction(setupVersion, setupDir, arch)
}
// preparing a report string
successMessages.push(getSuccessMessage(tool, installationInfo))
}