setup-cpp/src/python/actions_python.ts

52 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-04-25 07:39:43 +08:00
import { useCpythonVersion } from "setup-python/src/find-python"
import { findPyPyVersion } from "setup-python/src/find-pypy"
import { existsSync } from "fs"
2022-04-19 09:29:17 +08:00
import { info, warning } from "../utils/io/io"
2022-04-25 07:39:43 +08:00
import { debug } from "@actions/core"
import path from "path"
import { isGitHubCI } from "../utils/env/isci"
import { cacheDependencies } from "./actions_cache"
2021-09-20 20:24:17 +08:00
function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy-")
}
export async function setupActionsPython(version: string, _setupDir: string, arch: string) {
2022-04-19 09:29:17 +08:00
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
2022-04-25 07:39:43 +08:00
debug(`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env.AGENT_TOOLSDIRECTORY}`)
2022-04-19 09:29:17 +08:00
process.env.RUNNER_TOOL_CACHE = process.env.AGENT_TOOLSDIRECTORY
2021-09-20 20:24:17 +08:00
} else {
2022-04-25 07:39:43 +08:00
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-25 07:39:43 +08:00
if (version) {
let pythonVersion: string
if (isPyPyVersion(version)) {
const installed = await findPyPyVersion(version, arch)
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`
info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`)
} else {
const installed = await useCpythonVersion(version, arch)
pythonVersion = installed.version
info(`Successfully setup ${installed.impl} (${pythonVersion})`)
}
2022-04-25 07:39:43 +08:00
const cache = "pip" // core.getInput("cache") // package manager used for caching
2022-04-25 07:39:43 +08:00
await cacheDependencies(cache, pythonVersion)
2022-04-19 09:29:17 +08:00
}
if (isGitHubCI()) {
addPythonLoggingMatcher()
}
2021-09-20 20:24:17 +08:00
return undefined
}
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}`)
}