feat: add default version registry

This commit is contained in:
Amin Yahyaabadi 2021-09-16 06:36:35 -05:00
parent b55bf22468
commit a970eb0e44
5 changed files with 34 additions and 25 deletions

View File

@ -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<InstallationInfo> {
return setupBin("cmake", version === "true" ? default_cmake_version : version, getCmakePackageInfo, setupCppDir)
return setupBin("cmake", version, getCmakePackageInfo, setupCppDir)
}

15
src/default_versions.ts Normal file
View File

@ -0,0 +1,15 @@
const DefaultVersions: Record<string, string> = {
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
}
}

View File

@ -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<number> {
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<number> {
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<number> {
// 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<number> {
// 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)

View File

@ -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<void> {
const version = versionGiven === "true" ? default_msvc_version : versionGiven
if (process.platform !== "win32") {
return
}

View File

@ -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<InstallationInfo> {
return setupBin("ninja", version === "true" ? default_ninja_version : version, getNinjaPackageInfo, setupCppDir)
return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir)
}