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 */ /** Setup cmake */
export function setupCmake(version: string, setupCppDir: string): Promise<InstallationInfo> { 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 { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPython } from "./python/python" import { setupPython } from "./python/python"
import semverValid from "semver/functions/valid" import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions"
function maybeGetInput(key: string) { function maybeGetInput(key: string) {
const value = core.getInput(key.toLowerCase()) const value = core.getInput(key.toLowerCase())
@ -45,7 +46,7 @@ export async function main(): Promise<number> {
case "llvm": case "llvm":
case "clang": case "clang":
case "clang++": { case "clang++": {
await setupLLVM(version ?? "11", setupCppDir) await setupLLVM(getVersion("llvm", version), setupCppDir)
break break
} }
case "cl": case "cl":
@ -55,7 +56,7 @@ export async function main(): Promise<number> {
case "visualstudio": case "visualstudio":
case "visualcpp": case "visualcpp":
case "visualc++": { case "visualc++": {
await setupMSVC(version ?? "2019", setupCppDir) await setupMSVC(getVersion("msvc", version), setupCppDir)
break break
} }
default: { default: {
@ -67,49 +68,49 @@ export async function main(): Promise<number> {
// setup cmake // setup cmake
const cmakeVersion = maybeGetInput("cmake") const cmakeVersion = maybeGetInput("cmake")
if (cmakeVersion !== undefined) { if (cmakeVersion !== undefined) {
await setupCmake(cmakeVersion, setupCppDir) await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir)
} }
// setup ninja // setup ninja
const ninjaVersion = maybeGetInput("ninja") const ninjaVersion = maybeGetInput("ninja")
if (ninjaVersion !== undefined) { if (ninjaVersion !== undefined) {
await setupNinja(ninjaVersion, setupCppDir) await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir)
} }
// setup python (required for conan, meson, gcovr, etc.) // setup python (required for conan, meson, gcovr, etc.)
const pythonVersion = maybeGetInput("python") const pythonVersion = maybeGetInput("python")
if (pythonVersion !== undefined) { if (pythonVersion !== undefined) {
await setupPython(pythonVersion, arch) await setupPython(getVersion("python", pythonVersion), arch)
} }
// setup conan // setup conan
const conanVersion = maybeGetInput("conan") const conanVersion = maybeGetInput("conan")
if (conanVersion !== undefined) { if (conanVersion !== undefined) {
await setupConan(conanVersion) await setupConan(getVersion("conan", conanVersion))
} }
// setup meson // setup meson
const mesonVersion = maybeGetInput("meson") const mesonVersion = maybeGetInput("meson")
if (mesonVersion !== undefined) { if (mesonVersion !== undefined) {
await setupMeson(mesonVersion) await setupMeson(getVersion("meson", mesonVersion))
} }
// setup gcovr // setup gcovr
const gcovrVersion = maybeGetInput("gcovr") const gcovrVersion = maybeGetInput("gcovr")
if (gcovrVersion !== undefined) { if (gcovrVersion !== undefined) {
await setupGcovr(gcovrVersion) await setupGcovr(getVersion("gcovr", gcovrVersion))
} }
// setup opencppCoverage // setup opencppCoverage
const opencppCoverageVersion = maybeGetInput("opencppcoverage") const opencppCoverageVersion = maybeGetInput("opencppcoverage")
if (opencppCoverageVersion !== undefined) { if (opencppCoverageVersion !== undefined) {
await setupOpencppcoverage(opencppCoverageVersion) await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion))
} }
// setup llvm // setup llvm
const llvmVersion = maybeGetInput("llvm") const llvmVersion = maybeGetInput("llvm")
if (llvmVersion !== undefined) { if (llvmVersion !== undefined) {
await setupLLVM(llvmVersion, setupCppDir) await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir)
} }
// setup chocolatey (required for installing msvc) // setup chocolatey (required for installing msvc)
@ -127,25 +128,25 @@ export async function main(): Promise<number> {
// setup ccache // setup ccache
const ccacheVersion = maybeGetInput("ccache") const ccacheVersion = maybeGetInput("ccache")
if (ccacheVersion !== undefined) { if (ccacheVersion !== undefined) {
await setupCcache(ccacheVersion) await setupCcache(getVersion("ccache", ccacheVersion))
} }
// setup doxygen // setup doxygen
const doxygenVersion = maybeGetInput("doxygen") const doxygenVersion = maybeGetInput("doxygen")
if (doxygenVersion !== undefined) { if (doxygenVersion !== undefined) {
await setupDoxygen(doxygenVersion) await setupDoxygen(getVersion("doxygen", doxygenVersion))
} }
// setup cppCheck // setup cppCheck
const cppCheckVersion = maybeGetInput("cppcheck") const cppCheckVersion = maybeGetInput("cppcheck")
if (cppCheckVersion !== undefined) { if (cppCheckVersion !== undefined) {
await setupCppcheck(cppCheckVersion) await setupCppcheck(getVersion("cppcheck", cppCheckVersion))
} }
// setup msvc // setup msvc
const msvcVersion = maybeGetInput("msvc") const msvcVersion = maybeGetInput("msvc")
if (msvcVersion !== undefined) { if (msvcVersion !== undefined) {
await setupMSVC(msvcVersion) await setupMSVC(getVersion("msvc", msvcVersion))
} }
} catch (err) { } catch (err) {
core.error(err as string | Error) core.error(err as string | Error)

View File

@ -4,7 +4,7 @@ import { exportVariable } from "@actions/core"
import { existsSync } from "fs" import { existsSync } from "fs"
import { arch as osArch } from "os" import { arch as osArch } from "os"
type MSVCVersion = "2015" | "2017" | "2019" | "true" | string type MSVCVersion = "2015" | "2017" | "2019" | string
function getArch(arch: string): string { function getArch(arch: string): string {
switch (arch) { switch (arch) {
@ -22,16 +22,13 @@ function getArch(arch: string): string {
} }
} }
const default_msvc_version = "2019"
export async function setupMSVC( export async function setupMSVC(
versionGiven: MSVCVersion, version: MSVCVersion,
sdk?: string, sdk?: string,
uwp?: boolean, uwp?: boolean,
spectre?: boolean, spectre?: boolean,
arch = osArch() arch = osArch()
): Promise<void> { ): Promise<void> {
const version = versionGiven === "true" ? default_msvc_version : versionGiven
if (process.platform !== "win32") { if (process.platform !== "win32") {
return 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> { 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)
} }