chore: improve the types for setups and tools

This commit is contained in:
Amin Yahyaabadi 2021-09-17 12:12:33 -05:00
parent c4e699eee8
commit 736836f507
2 changed files with 27 additions and 31 deletions

View File

@ -15,6 +15,6 @@ export function getVersion(name: string, version: string | undefined) {
if (version === "true" || (version === undefined && name in DefaultVersions)) { if (version === "true" || (version === undefined && name in DefaultVersions)) {
return DefaultVersions[name] return DefaultVersions[name]
} else { } else {
return version return version ?? ""
} }
} }

View File

@ -16,27 +16,8 @@ import { setupPython } from "./python/python"
import semverValid from "semver/functions/valid" import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions" import { getVersion } from "./default_versions"
import { InstallationInfo } from "./utils/setup/setupBin"
import { setupGcc } from "./gcc/gcc" import { setupGcc } from "./gcc/gcc"
const tools = [
"cmake",
"ninja",
"python",
"conan",
"meson",
"gcovr",
"opencppcoverage",
"llvm",
"gcc",
"choco",
"brew",
"ccache",
"doxygen",
"cppcheck",
"msvc",
]
const setups = { const setups = {
cmake: setupCmake, cmake: setupCmake,
ninja: setupNinja, ninja: setupNinja,
@ -53,16 +34,29 @@ const setups = {
doxygen: setupDoxygen, doxygen: setupDoxygen,
cppcheck: setupCppcheck, cppcheck: setupCppcheck,
msvc: setupMSVC, msvc: setupMSVC,
} as Record< }
string,
(
version: string | undefined,
setupCppDir: string,
...args: unknown[]
) => Promise<InstallationInfo> | Promise<void> | void
>
function maybeGetInput(key: string) { const tools: Array<keyof typeof setups> = [
"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()) const value = core.getInput(key.toLowerCase())
if (value !== "false" && value !== "") { if (value !== "false" && value !== "") {
return value return value
@ -131,10 +125,12 @@ export async function main(): Promise<number> {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (installationInfo !== undefined) { if (installationInfo !== undefined) {
let success = `${tool} was successfully installed` 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}` success += `\nThe installation direcotry is ${installationInfo.installDir}`
} }
if (installationInfo.binDir) { if (installationInfo.binDir !== "") {
success += `\nThe binary direcotry is ${installationInfo.binDir}` success += `\nThe binary direcotry is ${installationInfo.binDir}`
} }
toolsSucceeded.push(success) toolsSucceeded.push(success)