mirror of https://github.com/aminya/setup-cpp
feat: install python3 if needed
This commit is contained in:
parent
bfeb0cd211
commit
edd8e55e9a
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue