fix: use sudo for pip if available

This commit is contained in:
Amin Yahyaabadi 2021-09-16 15:33:30 -05:00
parent 53b53fef98
commit cd775009da
2 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import { addPath, info } from "@actions/core"
import { setupPython } from "../../python/python"
import { isBinUptoDate } from "./version"
import { join } from "path"
import { mightSudo } from "./sudo"
let pip: string | undefined
@ -24,7 +25,10 @@ export async function setupPipPack(name: string, version?: string) {
}
}
const exit = await exec(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name])
const exit = await exec(mightSudo(pip), [
"install",
version !== undefined && version !== "" ? `${name}==${version}` : name,
])
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
}

View File

@ -10,8 +10,12 @@ export function isRoot(): boolean {
}
export function mightSudo(command: string) {
if (isRoot()) {
return `sudo ${command}`
try {
if (isRoot()) {
return `sudo ${command}`
}
} catch {
// ignore
}
return command
}