2021-12-05 22:16:28 +08:00
|
|
|
import * as finder from "setup-python/src/find-python"
|
|
|
|
|
import * as finderPyPy from "setup-python/src/find-pypy"
|
2022-02-12 08:58:50 +08:00
|
|
|
import { existsSync } from "fs"
|
2022-04-19 09:29:17 +08:00
|
|
|
import { info, warning } from "../utils/io/io"
|
|
|
|
|
import * as core from "@actions/core"
|
2022-02-12 08:58:50 +08:00
|
|
|
import path from "path"
|
|
|
|
|
import { isGitHubCI } from "../utils/env/isci"
|
2022-04-19 09:29:17 +08:00
|
|
|
import { isCacheFeatureAvailable } from "setup-python/src/utils"
|
|
|
|
|
import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
|
2021-09-20 20:24:17 +08:00
|
|
|
|
|
|
|
|
function isPyPyVersion(versionSpec: string) {
|
|
|
|
|
return versionSpec.startsWith("pypy-")
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 09:29:17 +08:00
|
|
|
async function cacheDependencies(cache: string, pythonVersion: string) {
|
|
|
|
|
const cacheDependencyPath = undefined // core.getInput("cache-dependency-path") || undefined
|
|
|
|
|
const cacheDistributor = getCacheDistributor(cache, pythonVersion, cacheDependencyPath)
|
|
|
|
|
await cacheDistributor.restoreCache()
|
|
|
|
|
}
|
2022-02-05 03:43:56 +08:00
|
|
|
|
2021-11-22 02:46:34 +08:00
|
|
|
export async function setupActionsPython(version: string, _setupDir: string, arch: string) {
|
2022-04-19 09:29:17 +08:00
|
|
|
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
|
|
|
|
|
core.debug(`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env.AGENT_TOOLSDIRECTORY}`)
|
|
|
|
|
process.env.RUNNER_TOOL_CACHE = process.env.AGENT_TOOLSDIRECTORY
|
2021-09-20 20:24:17 +08:00
|
|
|
} else {
|
2022-04-19 09:29:17 +08:00
|
|
|
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env.RUNNER_TOOL_CACHE}`)
|
2021-09-20 20:24:17 +08:00
|
|
|
}
|
2022-04-19 09:29:17 +08:00
|
|
|
try {
|
|
|
|
|
if (version) {
|
|
|
|
|
let pythonVersion: string
|
|
|
|
|
if (isPyPyVersion(version)) {
|
|
|
|
|
const installed = await finderPyPy.findPyPyVersion(version, arch)
|
|
|
|
|
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`
|
|
|
|
|
info(
|
|
|
|
|
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
const installed = await finder.useCpythonVersion(version, arch)
|
|
|
|
|
pythonVersion = installed.version
|
|
|
|
|
info(`Successfully setup ${installed.impl} (${pythonVersion})`)
|
|
|
|
|
}
|
2022-02-05 03:43:56 +08:00
|
|
|
|
2022-04-19 09:29:17 +08:00
|
|
|
const cache = "pip" // core.getInput("cache") // package manager used for caching
|
|
|
|
|
if (isCacheFeatureAvailable()) {
|
|
|
|
|
await cacheDependencies(cache, pythonVersion)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
core.setFailed((err as Error).message)
|
|
|
|
|
}
|
2022-02-05 03:43:56 +08:00
|
|
|
|
2022-02-12 08:58:50 +08:00
|
|
|
if (isGitHubCI()) {
|
|
|
|
|
addPythonLoggingMatcher()
|
|
|
|
|
}
|
2022-02-05 03:43:56 +08:00
|
|
|
|
2021-09-20 20:24:17 +08:00
|
|
|
return undefined
|
|
|
|
|
}
|
2022-02-12 08:58:50 +08:00
|
|
|
|
|
|
|
|
function addPythonLoggingMatcher() {
|
|
|
|
|
const matcherPath = path.join(__dirname, "python_matcher.json")
|
|
|
|
|
if (!existsSync(matcherPath)) {
|
|
|
|
|
return warning("the python_matcher.json file does not exist in the same folder as setup_cpp.js")
|
|
|
|
|
}
|
|
|
|
|
info(`::add-matcher::${matcherPath}`)
|
|
|
|
|
}
|