-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinputs.ts
More file actions
66 lines (60 loc) · 2.28 KB
/
Copy pathinputs.ts
File metadata and controls
66 lines (60 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { getInput, getBooleanInput } from "@actions/core";
import { parse as parseYaml } from "yaml";
import { z } from "zod/mini";
import { parsePackageManager } from "./ci/package-manager.js";
import { parseNodeManager } from "./ci/node-manager.js";
import type { Inputs, RunInstall } from "./types.js";
import { RunInstallInputSchema } from "./types.js";
export function getInputs(): Inputs {
const nodeVersion = getInput("node-version") || undefined;
const nodeVersionFile = getInput("node-version-file") || undefined;
const nodeManager = parseNodeManager(getInput("node-manager"));
if (nodeManager === false && (nodeVersion || nodeVersionFile)) {
throw new Error(
"node-manager: false cannot be combined with node-version or node-version-file: installing a Node.js version requires the Vite+ Node.js manager.",
);
}
return {
// Keep raw here (may be empty); the effective version, including any
// version-file resolution and the "latest" fallback, is computed in runMain.
version: getInput("version"),
versionFile: getInput("version-file") || undefined,
nodeVersion,
nodeVersionFile,
nodeManager,
packageManager: parsePackageManager(getInput("package-manager")),
workingDirectory: getInput("working-directory") || undefined,
runInstall: parseRunInstall(getInput("run-install")),
sfw: getBooleanInput("sfw"),
cache: getBooleanInput("cache"),
cacheSave: getBooleanInput("cache-save"),
cacheDependencyPath: getInput("cache-dependency-path") || undefined,
registryUrl: getInput("registry-url") || undefined,
scope: getInput("scope") || undefined,
};
}
function parseRunInstall(input: string): RunInstall[] {
if (!input || input === "false" || input === "null") {
return [];
}
// Handle boolean true
if (input === "true") {
return [{}];
}
// Parse YAML/JSON input
const parsed: unknown = parseYaml(input);
try {
const result = RunInstallInputSchema.parse(parsed);
if (!result) return [];
if (result === true) return [{}];
if (Array.isArray(result)) return result;
return [result];
} catch (error) {
if (error instanceof z.core.$ZodError) {
throw new Error(
`Invalid run-install input: ${error.issues.map((e) => e.message).join(", ")}`,
);
}
throw error;
}
}