From edd8e55e9a97c3c6dc21ffade7e3c3ae4552371c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 15 Sep 2021 03:36:37 -0500 Subject: [PATCH] feat: install python3 if needed --- src/utils/setup/setupPipPack.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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) {