From 44478af66e2a4f17a6dd9e5308256b27e2970d89 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 20 Sep 2021 07:24:17 -0500 Subject: [PATCH] refactor: separate setupActionsPython --- src/python/actions_python.ts | 23 +++++++++++++++++++++++ src/python/python.ts | 24 +++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 src/python/actions_python.ts diff --git a/src/python/actions_python.ts b/src/python/actions_python.ts new file mode 100644 index 00000000..3ea33df3 --- /dev/null +++ b/src/python/actions_python.ts @@ -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 +} diff --git a/src/python/python.ts b/src/python/python.ts index 7b769639..a38ed1a6 100644 --- a/src/python/python.ts +++ b/src/python/python.ts @@ -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) }