Skip to content

Commit 736836f

Browse files
committed
chore: improve the types for setups and tools
1 parent c4e699e commit 736836f

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

src/default_versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export function getVersion(name: string, version: string | undefined) {
1515
if (version === "true" || (version === undefined && name in DefaultVersions)) {
1616
return DefaultVersions[name]
1717
} else {
18-
return version
18+
return version ?? ""
1919
}
2020
}

src/main.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,27 @@ import { setupPython } from "./python/python"
1616

1717
import semverValid from "semver/functions/valid"
1818
import { getVersion } from "./default_versions"
19-
import { InstallationInfo } from "./utils/setup/setupBin"
2019
import { setupGcc } from "./gcc/gcc"
2120

22-
const tools = [
21+
const setups = {
22+
cmake: setupCmake,
23+
ninja: setupNinja,
24+
python: setupPython,
25+
conan: setupConan,
26+
meson: setupMeson,
27+
gcovr: setupGcovr,
28+
opencppcoverage: setupOpencppcoverage,
29+
llvm: setupLLVM,
30+
gcc: setupGcc,
31+
choco: setupChocolatey,
32+
brew: setupBrew,
33+
ccache: setupCcache,
34+
doxygen: setupDoxygen,
35+
cppcheck: setupCppcheck,
36+
msvc: setupMSVC,
37+
}
38+
39+
const tools: Array<keyof typeof setups> = [
2340
"cmake",
2441
"ninja",
2542
"python",
@@ -37,32 +54,9 @@ const tools = [
3754
"msvc",
3855
]
3956

40-
const setups = {
41-
cmake: setupCmake,
42-
ninja: setupNinja,
43-
python: setupPython,
44-
conan: setupConan,
45-
meson: setupMeson,
46-
gcovr: setupGcovr,
47-
opencppcoverage: setupOpencppcoverage,
48-
llvm: setupLLVM,
49-
gcc: setupGcc,
50-
choco: setupChocolatey,
51-
brew: setupBrew,
52-
ccache: setupCcache,
53-
doxygen: setupDoxygen,
54-
cppcheck: setupCppcheck,
55-
msvc: setupMSVC,
56-
} as Record<
57-
string,
58-
(
59-
version: string | undefined,
60-
setupCppDir: string,
61-
...args: unknown[]
62-
) => Promise<InstallationInfo> | Promise<void> | void
63-
>
57+
type Inputs = "compiler" | keyof typeof setups
6458

65-
function maybeGetInput(key: string) {
59+
function maybeGetInput(key: Inputs) {
6660
const value = core.getInput(key.toLowerCase())
6761
if (value !== "false" && value !== "") {
6862
return value
@@ -131,10 +125,12 @@ export async function main(): Promise<number> {
131125
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
132126
if (installationInfo !== undefined) {
133127
let success = `${tool} was successfully installed`
134-
if (installationInfo.installDir !== undefined) {
128+
if ("installDir" in installationInfo) {
129+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
130+
// @ts-ignore typescript is confused about the existence of installDir
135131
success += `\nThe installation direcotry is ${installationInfo.installDir}`
136132
}
137-
if (installationInfo.binDir) {
133+
if (installationInfo.binDir !== "") {
138134
success += `\nThe binary direcotry is ${installationInfo.binDir}`
139135
}
140136
toolsSucceeded.push(success)

0 commit comments

Comments
 (0)