2021-09-15 04:23:45 +08:00
|
|
|
import * as core from "@actions/core"
|
2021-09-18 20:39:59 +08:00
|
|
|
import { addPath } from "../utils/path/addPath"
|
|
|
|
|
import { setupAptPack } from "../utils/setup/setupAptPack"
|
|
|
|
|
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|
|
|
|
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
|
|
|
|
import hasha from "hasha"
|
|
|
|
|
import { join } from "path"
|
2022-01-18 06:23:33 +08:00
|
|
|
import { isGitHubCI } from "../utils/env/isci"
|
2021-09-15 04:23:45 +08:00
|
|
|
|
2021-11-22 02:46:34 +08:00
|
|
|
export function setupPython(version: string, setupDir: string, arch: string) {
|
2022-01-18 06:23:33 +08:00
|
|
|
if (!isGitHubCI()) {
|
2021-09-18 21:35:41 +08:00
|
|
|
// TODO parse versoin
|
2021-11-22 02:46:34 +08:00
|
|
|
return setupPythonViaSystem("", setupDir, arch)
|
2021-09-18 20:50:31 +08:00
|
|
|
}
|
2021-09-15 04:23:45 +08:00
|
|
|
try {
|
2021-11-22 06:22:27 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
|
const { setupActionsPython } = require("./actions_python") as typeof import("./actions_python")
|
2021-11-22 02:46:34 +08:00
|
|
|
return setupActionsPython(version, setupDir, arch)
|
2021-09-15 04:23:45 +08:00
|
|
|
} catch (err) {
|
2021-11-22 02:46:34 +08:00
|
|
|
return setupPythonViaSystem(version, setupDir, arch)
|
2021-09-18 20:39:59 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 02:46:34 +08:00
|
|
|
export async function setupPythonViaSystem(version: string, setupDir: string, arch: string) {
|
2021-09-18 20:39:59 +08:00
|
|
|
switch (process.platform) {
|
|
|
|
|
case "win32": {
|
|
|
|
|
// Get an unique output directory name from the URL.
|
|
|
|
|
const key: string = await hasha.async(version + arch, { algorithm: "md5" })
|
2021-11-22 02:46:34 +08:00
|
|
|
const installDir = join(setupDir, key, "python")
|
2021-09-18 20:39:59 +08:00
|
|
|
const binDir = installDir
|
|
|
|
|
await setupChocoPack("python3", version, [`/InstallDir:${installDir}`])
|
|
|
|
|
|
|
|
|
|
// Adding the bin dir to the path
|
|
|
|
|
/** The directory which the tool is installed to */
|
2021-09-20 20:35:17 +08:00
|
|
|
activateWinPython(binDir)
|
2021-09-18 20:39:59 +08:00
|
|
|
|
|
|
|
|
return { installDir, binDir }
|
|
|
|
|
}
|
|
|
|
|
case "darwin": {
|
|
|
|
|
return setupBrewPack("python3", version)
|
|
|
|
|
}
|
|
|
|
|
case "linux": {
|
|
|
|
|
const installInfo = await setupAptPack("python3", version)
|
|
|
|
|
await setupAptPack("python3-pip")
|
|
|
|
|
return installInfo
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw new Error(`Unsupported platform`)
|
|
|
|
|
}
|
2021-09-15 04:23:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-20 20:35:17 +08:00
|
|
|
|
|
|
|
|
function activateWinPython(binDir: string) {
|
|
|
|
|
core.info(`Add ${binDir} to PATH`)
|
|
|
|
|
addPath(binDir)
|
|
|
|
|
}
|