From 736836f507d1cf1a9baf2c765730060f45c55a56 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 17 Sep 2021 12:12:33 -0500 Subject: [PATCH] chore: improve the types for setups and tools --- src/default_versions.ts | 2 +- src/main.ts | 56 +++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/default_versions.ts b/src/default_versions.ts index 338b1db6..fc71e139 100644 --- a/src/default_versions.ts +++ b/src/default_versions.ts @@ -15,6 +15,6 @@ export function getVersion(name: string, version: string | undefined) { if (version === "true" || (version === undefined && name in DefaultVersions)) { return DefaultVersions[name] } else { - return version + return version ?? "" } } diff --git a/src/main.ts b/src/main.ts index 43fe95c9..e0687b3c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,27 +16,8 @@ import { setupPython } from "./python/python" import semverValid from "semver/functions/valid" import { getVersion } from "./default_versions" -import { InstallationInfo } from "./utils/setup/setupBin" import { setupGcc } from "./gcc/gcc" -const tools = [ - "cmake", - "ninja", - "python", - "conan", - "meson", - "gcovr", - "opencppcoverage", - "llvm", - "gcc", - "choco", - "brew", - "ccache", - "doxygen", - "cppcheck", - "msvc", -] - const setups = { cmake: setupCmake, ninja: setupNinja, @@ -53,16 +34,29 @@ const setups = { doxygen: setupDoxygen, cppcheck: setupCppcheck, msvc: setupMSVC, -} as Record< - string, - ( - version: string | undefined, - setupCppDir: string, - ...args: unknown[] - ) => Promise | Promise | void -> +} -function maybeGetInput(key: string) { +const tools: Array = [ + "cmake", + "ninja", + "python", + "conan", + "meson", + "gcovr", + "opencppcoverage", + "llvm", + "gcc", + "choco", + "brew", + "ccache", + "doxygen", + "cppcheck", + "msvc", +] + +type Inputs = "compiler" | keyof typeof setups + +function maybeGetInput(key: Inputs) { const value = core.getInput(key.toLowerCase()) if (value !== "false" && value !== "") { return value @@ -131,10 +125,12 @@ export async function main(): Promise { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (installationInfo !== undefined) { let success = `${tool} was successfully installed` - if (installationInfo.installDir !== undefined) { + if ("installDir" in installationInfo) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore typescript is confused about the existence of installDir success += `\nThe installation direcotry is ${installationInfo.installDir}` } - if (installationInfo.binDir) { + if (installationInfo.binDir !== "") { success += `\nThe binary direcotry is ${installationInfo.binDir}` } toolsSucceeded.push(success)