diff --git a/src/brew/brew.ts b/src/brew/brew.ts index 90cc93ee..d67cbcaf 100644 --- a/src/brew/brew.ts +++ b/src/brew/brew.ts @@ -1,7 +1,8 @@ import { execFileSync } from "child_process" import which from "which" -export function setupBrew() { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupBrew(_version: string, _setupCppDir: string, _arch: string) { if (!["darwin", "linux"].includes(process.platform)) { return } diff --git a/src/ccache/ccache.ts b/src/ccache/ccache.ts index 171151c9..f035a080 100644 --- a/src/ccache/ccache.ts +++ b/src/ccache/ccache.ts @@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupChocoPack } from "../utils/setup/setupChocoPack" -export function setupCcache(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupCcache(version: string, _setupCppDir: string, _arch: string) { switch (process.platform) { case "win32": { return setupChocoPack("ccache", version) diff --git a/src/chocolatey/chocolatey.ts b/src/chocolatey/chocolatey.ts index 5f82b707..dfcd48d5 100644 --- a/src/chocolatey/chocolatey.ts +++ b/src/chocolatey/chocolatey.ts @@ -1,7 +1,8 @@ import { exec } from "@actions/exec" import which from "which" -export async function setupChocolatey() { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupChocolatey(_version: string, _setupCppDir: string, _arch: string) { if (process.platform !== "win32") { return } diff --git a/src/cmake/cmake.ts b/src/cmake/cmake.ts index 9ae31115..b8e33195 100644 --- a/src/cmake/cmake.ts +++ b/src/cmake/cmake.ts @@ -59,6 +59,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa } /** Setup cmake */ -export function setupCmake(version: string, setupCppDir: string): Promise { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupCmake(version: string, setupCppDir: string, _arch: string): Promise { return setupBin("cmake", version, getCmakePackageInfo, setupCppDir) } diff --git a/src/conan/conan.ts b/src/conan/conan.ts index 224cf681..04510977 100644 --- a/src/conan/conan.ts +++ b/src/conan/conan.ts @@ -1,5 +1,6 @@ import { setupPipPack } from "../utils/setup/setupPipPack" -export async function setupConan(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupConan(version: string | undefined, _setupCppDir: string, _arch: string) { await setupPipPack("conan", version) } diff --git a/src/cppcheck/cppcheck.ts b/src/cppcheck/cppcheck.ts index b108e007..c9a0d989 100644 --- a/src/cppcheck/cppcheck.ts +++ b/src/cppcheck/cppcheck.ts @@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupChocoPack } from "../utils/setup/setupChocoPack" -export function setupCppcheck(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupCppcheck(version: string | undefined, _setupCppDir: string, _arch: string) { switch (process.platform) { case "win32": { return setupChocoPack("cppcheck", version) diff --git a/src/default_versions.ts b/src/default_versions.ts index 0c843235..8ebd1ea6 100644 --- a/src/default_versions.ts +++ b/src/default_versions.ts @@ -7,7 +7,7 @@ const DefaultVersions: Record = { /** 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) { + if (version === "true" || (version === undefined && name in DefaultVersions)) { return DefaultVersions[name] } else { return version diff --git a/src/doxygen/doxygen.ts b/src/doxygen/doxygen.ts index 87de8087..8ec02862 100644 --- a/src/doxygen/doxygen.ts +++ b/src/doxygen/doxygen.ts @@ -2,7 +2,8 @@ import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupChocoPack } from "../utils/setup/setupChocoPack" -export async function setupDoxygen(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupDoxygen(version: string | undefined, _setupCppDir: string, _arch: string) { switch (process.platform) { case "win32": { await setupChocoPack("graphviz", version) diff --git a/src/gcovr/gcovr.ts b/src/gcovr/gcovr.ts index 93347e0a..dea71581 100644 --- a/src/gcovr/gcovr.ts +++ b/src/gcovr/gcovr.ts @@ -1,5 +1,6 @@ import { setupPipPack } from "../utils/setup/setupPipPack" -export async function setupGcovr(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupGcovr(version: string | undefined, _setupCppDir: string, _arch: string) { await setupPipPack("gcovr", version) } diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index b9c7ce12..57cac8ff 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -233,8 +233,13 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P } } -export async function setupLLVM(version: string, directoryGiven?: string): Promise { - let directory = directoryGiven +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupLLVM( + version: string, + _setupCppDir: string | undefined, + _arch: string +): Promise { + let directory = _setupCppDir if (directory === "" || directory === undefined) { directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY } diff --git a/src/main.ts b/src/main.ts index a086903d..b9a82f66 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,8 +13,34 @@ import { setupMSVC } from "./msvc/msvc" 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" +import { InstallationInfo } from "./utils/setup/setupBin" + +const setups = { + cmake: setupCmake, + ninja: setupNinja, + python: setupPython, + conan: setupConan, + meson: setupMeson, + gcovr: setupGcovr, + opencppcoverage: setupOpencppcoverage, + llvm: setupLLVM, + choco: setupChocolatey, + brew: setupBrew, + ccache: setupCcache, + doxygen: setupDoxygen, + cppcheck: setupCppcheck, + msvc: setupMSVC, +} as Record< + string, + ( + version: string | undefined, + setupCppDir: string, + ...args: unknown[] + ) => Promise | Promise | void +> function maybeGetInput(key: string) { const value = core.getInput(key.toLowerCase()) @@ -46,7 +72,7 @@ export async function main(): Promise { case "llvm": case "clang": case "clang++": { - await setupLLVM(getVersion("llvm", version), setupCppDir) + await setupLLVM(getVersion("llvm", version) as string, setupCppDir, arch) break } case "cl": @@ -56,7 +82,7 @@ export async function main(): Promise { case "visualstudio": case "visualcpp": case "visualc++": { - await setupMSVC(getVersion("msvc", version), setupCppDir) + await setupMSVC(getVersion("msvc", version) as string, setupCppDir, arch) break } default: { @@ -65,88 +91,28 @@ export async function main(): Promise { } } - // setup cmake - const cmakeVersion = maybeGetInput("cmake") - if (cmakeVersion !== undefined) { - await setupCmake(getVersion("cmake", cmakeVersion), setupCppDir) - } - - // setup ninja - const ninjaVersion = maybeGetInput("ninja") - if (ninjaVersion !== undefined) { - await setupNinja(getVersion("ninja", ninjaVersion), setupCppDir) - } - - // setup python (required for conan, meson, gcovr, etc.) - const pythonVersion = maybeGetInput("python") - if (pythonVersion !== undefined) { - await setupPython(getVersion("python", pythonVersion), arch) - } - - // setup conan - const conanVersion = maybeGetInput("conan") - if (conanVersion !== undefined) { - await setupConan(getVersion("conan", conanVersion)) - } - - // setup meson - const mesonVersion = maybeGetInput("meson") - if (mesonVersion !== undefined) { - await setupMeson(getVersion("meson", mesonVersion)) - } - - // setup gcovr - const gcovrVersion = maybeGetInput("gcovr") - if (gcovrVersion !== undefined) { - await setupGcovr(getVersion("gcovr", gcovrVersion)) - } - - // setup opencppCoverage - const opencppCoverageVersion = maybeGetInput("opencppcoverage") - if (opencppCoverageVersion !== undefined) { - await setupOpencppcoverage(getVersion("opencppcoverage", opencppCoverageVersion)) - } - - // setup llvm - const llvmVersion = maybeGetInput("llvm") - if (llvmVersion !== undefined) { - await setupLLVM(getVersion("llvm", llvmVersion), setupCppDir) - } - - // setup chocolatey (required for installing msvc) - const chocoVersion = maybeGetInput("choco") - if (chocoVersion !== undefined) { - await setupChocolatey() - } - - // setup brew - const brewVersion = maybeGetInput("brew") - if (brewVersion !== undefined) { - setupBrew() - } - - // setup ccache - const ccacheVersion = maybeGetInput("ccache") - if (ccacheVersion !== undefined) { - await setupCcache(getVersion("ccache", ccacheVersion)) - } - - // setup doxygen - const doxygenVersion = maybeGetInput("doxygen") - if (doxygenVersion !== undefined) { - await setupDoxygen(getVersion("doxygen", doxygenVersion)) - } - - // setup cppCheck - const cppCheckVersion = maybeGetInput("cppcheck") - if (cppCheckVersion !== undefined) { - await setupCppcheck(getVersion("cppcheck", cppCheckVersion)) - } - - // setup msvc - const msvcVersion = maybeGetInput("msvc") - if (msvcVersion !== undefined) { - await setupMSVC(getVersion("msvc", msvcVersion)) + for (const tool of [ + "cmake", + "ninja", + "python", + "conan", + "meson", + "gcovr", + "opencppcoverage", + "llvm", + "choco", + "brew", + "ccache", + "doxygen", + "cppcheck", + "msvc", + ]) { + const version = maybeGetInput(tool) + if (version !== undefined) { + const setupFunction = setups[tool] + // eslint-disable-next-line no-await-in-loop + await setupFunction(getVersion(tool, version), setupCppDir, arch) + } } } catch (err) { core.error(err as string | Error) diff --git a/src/meson/meson.ts b/src/meson/meson.ts index 6fbf6ac4..963dab23 100644 --- a/src/meson/meson.ts +++ b/src/meson/meson.ts @@ -1,5 +1,6 @@ import { setupPipPack } from "../utils/setup/setupPipPack" -export async function setupMeson(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupMeson(version: string | undefined, _setupCppDir: string, _arch: string) { await setupPipPack("meson", version) } diff --git a/src/msvc/msvc.ts b/src/msvc/msvc.ts index 94afdf92..f313ab58 100644 --- a/src/msvc/msvc.ts +++ b/src/msvc/msvc.ts @@ -24,10 +24,11 @@ function getArch(arch: string): string { export async function setupMSVC( version: MSVCVersion, + _setupCppDir: string, + arch: string, sdk?: string, uwp?: boolean, - spectre?: boolean, - arch = osArch() + spectre?: boolean ): Promise { if (process.platform !== "win32") { return diff --git a/src/ninja/ninja.ts b/src/ninja/ninja.ts index dddad01d..d6e4e27d 100644 --- a/src/ninja/ninja.ts +++ b/src/ninja/ninja.ts @@ -26,6 +26,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag } } -export function setupNinja(version: string, setupCppDir: string): Promise { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function setupNinja(version: string, setupCppDir: string, _arch: string): Promise { return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir) } diff --git a/src/opencppcoverage/opencppcoverage.ts b/src/opencppcoverage/opencppcoverage.ts index 9478ea59..55766bb9 100644 --- a/src/opencppcoverage/opencppcoverage.ts +++ b/src/opencppcoverage/opencppcoverage.ts @@ -1,7 +1,8 @@ import { addPath } from "@actions/core" import { setupChocoPack } from "../utils/setup/setupChocoPack" -export async function setupOpencppcoverage(version?: string) { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export async function setupOpencppcoverage(version: string | undefined, _setupCppDir: string, _arch: string) { if (process.platform !== "win32") { return } diff --git a/src/python/python.ts b/src/python/python.ts index db34c7da..76467886 100644 --- a/src/python/python.ts +++ b/src/python/python.ts @@ -2,24 +2,21 @@ 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 * as os from "os" function isPyPyVersion(versionSpec: string) { return versionSpec.startsWith("pypy-") } -export async function setupPython(version?: string, arch: string = os.arch()) { +export async function setupPython(version: string, _setupCppDir: string, arch: string) { try { - if (version !== undefined && version !== "") { - 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})`) - } + 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(__dirname, "..", ".github") core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`)