refactor: separate setupActionsPython

This commit is contained in:
Amin Yahyaabadi 2021-09-20 07:24:17 -05:00
parent 3dd8e43133
commit 44478af66e
2 changed files with 26 additions and 21 deletions

View File

@ -0,0 +1,23 @@
import * as core from "@actions/core"
import * as finder from "./setup-python/src/find-python"
import * as finderPyPy from "./setup-python/src/find-pypy"
import * as path from "path"
function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy-")
}
export async function setupActionsPython(version: string, _setupCppDir: string, arch: string) {
if (isPyPyVersion(version)) {
const installed = await finderPyPy.findPyPyVersion(version, arch)
core.info(
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
)
} else {
const installed = await finder.findPythonVersion(version, arch)
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
}
const matchersPath = path.join("setup-pthon", ".github")
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)
return undefined
}

View File

@ -1,7 +1,4 @@
import * as core from "@actions/core"
import * as finder from "./setup-python/src/find-python"
import * as finderPyPy from "./setup-python/src/find-pypy"
import * as path from "path"
import { addPath } from "../utils/path/addPath"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
@ -9,30 +6,15 @@ import { setupChocoPack } from "../utils/setup/setupChocoPack"
import hasha from "hasha"
import { join } from "path"
import { isCI } from "../utils/env/isci"
import { setupActionsPython } from "./actions_python"
function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy-")
}
export async function setupPython(version: string, setupCppDir: string, arch: string) {
export function setupPython(version: string, setupCppDir: string, arch: string) {
if (!isCI()) {
// TODO parse versoin
return setupPythonViaSystem("", setupCppDir, arch)
}
try {
if (isPyPyVersion(version)) {
const installed = await finderPyPy.findPyPyVersion(version, arch)
core.info(
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
)
} else {
const installed = await finder.findPythonVersion(version, arch)
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
}
const matchersPath = path.join("setup-pthon", ".github")
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)
return undefined
return setupActionsPython(version, setupCppDir, arch)
} catch (err) {
return setupPythonViaSystem(version, setupCppDir, arch)
}