diff --git a/src/utils/setup/setupPipPack.ts b/src/utils/setup/setupPipPack.ts index 5f9358d0..3df6f168 100644 --- a/src/utils/setup/setupPipPack.ts +++ b/src/utils/setup/setupPipPack.ts @@ -1,11 +1,25 @@ +/* eslint-disable require-atomic-updates */ import { exec } from "@actions/exec" import which from "which" import { addPath, startGroup, endGroup } from "@actions/core" +import { setupPython } from "../../python/python" +import { isBinUptoDate } from "./version" + +let pip: string | undefined /** A function that installs a package using pip */ export async function setupPipPack(name: string, version?: string) { - // check if it exists - const pip = which.sync("pip3", { nothrow: true }) !== null ? "pip3" : "pip" + // setup python and pip if needed + if (pip === undefined) { + if (which.sync("pip3", { nothrow: true }) !== null) { + pip = "pip3" + } else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) { + pip = "pip" + } else { + await setupPython("3.x") + pip = "pip3" + } + } const exit = await exec(pip, ["install", version !== undefined ? `${name}==${version}` : name]) if (exit !== 0) {