From a970eb0e44d13e1bdc810be20ef62f1726d51f59 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 16 Sep 2021 06:36:35 -0500 Subject: [PATCH] feat: add default version registry --- src/cmake/cmake.ts | 4 +--- src/default_versions.ts | 15 +++++++++++++++ src/main.ts | 29 +++++++++++++++-------------- src/msvc/msvc.ts | 7 ++----- src/ninja/ninja.ts | 4 +--- 5 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 src/default_versions.ts diff --git a/src/cmake/cmake.ts b/src/cmake/cmake.ts index 7c4c2d13..9ae31115 100644 --- a/src/cmake/cmake.ts +++ b/src/cmake/cmake.ts @@ -58,9 +58,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa } } -const default_cmake_version = "3.20.2" - /** Setup cmake */ export function setupCmake(version: string, setupCppDir: string): Promise { - return setupBin("cmake", version === "true" ? default_cmake_version : version, getCmakePackageInfo, setupCppDir) + return setupBin("cmake", version, getCmakePackageInfo, setupCppDir) } diff --git a/src/default_versions.ts b/src/default_versions.ts new file mode 100644 index 00000000..0c843235 --- /dev/null +++ b/src/default_versions.ts @@ -0,0 +1,15 @@ +const DefaultVersions: Record = { + msvc: "2019", + llvm: "11", + ninja: "1.10.2", + cmake: "3.20.2", +} + +/** Get the default version if passed true or undefined, otherwise return the version itself */ +export function getVersion(name: string, version: string | undefined) { + if (version === "true" || version === undefined) { + return DefaultVersions[name] + } else { + return version + } +} diff --git a/src/main.ts b/src/main.ts index 84e26788..a086903d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ import { setupNinja } from "./ninja/ninja" import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage" import { setupPython } from "./python/python" import semverValid from "semver/functions/valid" +import { getVersion } from "./default_versions" function maybeGetInput(key: string) { const value = core.getInput(key.toLowerCase()) @@ -45,7 +46,7 @@ export async function main(): Promise { case "llvm": case "clang": case "clang++": { - await setupLLVM(version ?? "11", setupCppDir) + await setupLLVM(getVersion("llvm", version), setupCppDir) break } case "cl": @@ -55,7 +56,7 @@ export async function main(): Promise { case "visualstudio": case "visualcpp": case "visualc++": { - await setupMSVC(version ?? "2019", setupCppDir) + await setupMSVC(getVersion("msvc", version), setupCppDir) break } default: { @@ -67,49 +68,49 @@ export async function main(): Promise { // setup cmake const cmakeVersion = maybeGetInput("cmake") if (cmakeVersion !== undefined) { - await setupCmake(cmakeVersion, setupCppDir) + await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir) } // setup ninja const ninjaVersion = maybeGetInput("ninja") if (ninjaVersion !== undefined) { - await setupNinja(ninjaVersion, setupCppDir) + await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir) } // setup python (required for conan, meson, gcovr, etc.) const pythonVersion = maybeGetInput("python") if (pythonVersion !== undefined) { - await setupPython(pythonVersion, arch) + await setupPython(getVersion("python", pythonVersion), arch) } // setup conan const conanVersion = maybeGetInput("conan") if (conanVersion !== undefined) { - await setupConan(conanVersion) + await setupConan(getVersion("conan", conanVersion)) } // setup meson const mesonVersion = maybeGetInput("meson") if (mesonVersion !== undefined) { - await setupMeson(mesonVersion) + await setupMeson(getVersion("meson", mesonVersion)) } // setup gcovr const gcovrVersion = maybeGetInput("gcovr") if (gcovrVersion !== undefined) { - await setupGcovr(gcovrVersion) + await setupGcovr(getVersion("gcovr", gcovrVersion)) } // setup opencppCoverage const opencppCoverageVersion = maybeGetInput("opencppcoverage") if (opencppCoverageVersion !== undefined) { - await setupOpencppcoverage(opencppCoverageVersion) + await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion)) } // setup llvm const llvmVersion = maybeGetInput("llvm") if (llvmVersion !== undefined) { - await setupLLVM(llvmVersion, setupCppDir) + await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir) } // setup chocolatey (required for installing msvc) @@ -127,25 +128,25 @@ export async function main(): Promise { // setup ccache const ccacheVersion = maybeGetInput("ccache") if (ccacheVersion !== undefined) { - await setupCcache(ccacheVersion) + await setupCcache(getVersion("ccache", ccacheVersion)) } // setup doxygen const doxygenVersion = maybeGetInput("doxygen") if (doxygenVersion !== undefined) { - await setupDoxygen(doxygenVersion) + await setupDoxygen(getVersion("doxygen", doxygenVersion)) } // setup cppCheck const cppCheckVersion = maybeGetInput("cppcheck") if (cppCheckVersion !== undefined) { - await setupCppcheck(cppCheckVersion) + await setupCppcheck(getVersion("cppcheck", cppCheckVersion)) } // setup msvc const msvcVersion = maybeGetInput("msvc") if (msvcVersion !== undefined) { - await setupMSVC(msvcVersion) + await setupMSVC(getVersion("msvc", msvcVersion)) } } catch (err) { core.error(err as string | Error) diff --git a/src/msvc/msvc.ts b/src/msvc/msvc.ts index d68c547e..94afdf92 100644 --- a/src/msvc/msvc.ts +++ b/src/msvc/msvc.ts @@ -4,7 +4,7 @@ import { exportVariable } from "@actions/core" import { existsSync } from "fs" import { arch as osArch } from "os" -type MSVCVersion = "2015" | "2017" | "2019" | "true" | string +type MSVCVersion = "2015" | "2017" | "2019" | string function getArch(arch: string): string { switch (arch) { @@ -22,16 +22,13 @@ function getArch(arch: string): string { } } -const default_msvc_version = "2019" - export async function setupMSVC( - versionGiven: MSVCVersion, + version: MSVCVersion, sdk?: string, uwp?: boolean, spectre?: boolean, arch = osArch() ): Promise { - const version = versionGiven === "true" ? default_msvc_version : versionGiven if (process.platform !== "win32") { return } diff --git a/src/ninja/ninja.ts b/src/ninja/ninja.ts index ae11f103..dddad01d 100644 --- a/src/ninja/ninja.ts +++ b/src/ninja/ninja.ts @@ -26,8 +26,6 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag } } -const default_ninja_version = "1.10.2" - export function setupNinja(version: string, setupCppDir: string): Promise { - return setupBin("ninja", version === "true" ? default_ninja_version : version, getNinjaPackageInfo, setupCppDir) + return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir) }