@actions/exec#getExecOutput TypeScript Examples
The following examples show how to use
@actions/exec#getExecOutput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: macos-sdk.ts From setup-cpp with Apache License 2.0 | 6 votes |
export async function setupMacOSSDK() {
if (process.platform === "darwin") {
try {
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
const sdkroot = xcrun.stdout || xcrun.stderr
if (sdkroot) {
await addEnv("SDKROOT", sdkroot.trim())
} else {
error(`SDKROOT not set`)
}
} catch (e) {
error(e as Error | string)
}
}
}
Example #2
Source File: version.ts From setup-cpp with Apache License 2.0 | 6 votes |
/** Get the version of a binary */
export async function getBinVersion(file: string, versionRegex: RegExp = defaultVersionRegex) {
try {
const execout = await getExecOutput(file, ["--version"])
const version_output = execout.stdout || execout.stderr || ""
const version = version_output.trim().match(versionRegex)?.[1]
return version
} catch (e) {
console.error(e)
return undefined
}
}
Example #3
Source File: setupPipPack.ts From setup-cpp with Apache License 2.0 | 5 votes |
/** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pip`)
// setup python and pip if needed
if (python === undefined) {
if (which.sync("python3", { nothrow: true }) !== null) {
python = "python3"
} else if (which.sync("python", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
python = "python"
} else {
info("python3 was not found. Installing python")
await setupPython(getVersion("python", undefined), "", process.arch)
// try again
if (tried) {
throw new Error("Failed to install python")
}
tried = true
return setupPipPack(name, version)
}
if (process.platform === "win32") {
// downgrade pip on Windows
// https://github.com/pypa/pip/issues/10875#issuecomment-1030293005
execa.sync(python, ["-m", "pip", "install", "-U", "pip==21.3.1"], { stdio: "inherit" })
} else if (process.platform === "linux") {
// ensure that pip is installed on Linux (happens when python is found but pip not installed)
setupAptPack("python3-pip")
}
// install wheel (required for Conan, Meson, etc.)
execa.sync(python, ["-m", "pip", "install", "-U", "wheel"], { stdio: "inherit" })
}
execa.sync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
stdio: "inherit",
})
if (binDir === undefined) {
if (process.platform === "linux") {
binDir = "/home/runner/.local/bin/"
} else if (process.platform === "darwin") {
binDir = "/usr/local/bin/"
} else {
// windows or others
try {
binDir = join(
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
"Scripts"
)
} catch {
binDir = join(
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
"Scripts"
)
}
}
info(`${binDir} to PATH`)
await addPath(binDir)
}
return { binDir }
}