-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinputs.ts
More file actions
47 lines (42 loc) · 1.37 KB
/
inputs.ts
File metadata and controls
47 lines (42 loc) · 1.37 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
import { getInput, getBooleanInput } from "@actions/core";
import { parse as parseYaml } from "yaml";
import { z } from "zod";
import type { Inputs, RunInstall } from "./types.js";
import { RunInstallInputSchema } from "./types.js";
export function getInputs(): Inputs {
return {
version: getInput("version") || "latest",
nodeVersion: getInput("node-version") || undefined,
nodeVersionFile: getInput("node-version-file") || undefined,
runInstall: parseRunInstall(getInput("run-install")),
cache: getBooleanInput("cache"),
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.ZodError) {
throw new Error(
`Invalid run-install input: ${error.errors.map((e) => e.message).join(", ")}`,
);
}
throw error;
}
}