Parses and validates GitHub Actions inputs against a Zod schema.
For each key in the schema, the function attempts to read the value from:
@actions/core
getInput
The first non-undefined value is used. Values are then validated and transformed according to the provided Zod schema.
import { z } from "zod";import { parseInput } from "./parseInput";const schema = z.object({ mode: z.enum(["warn", "fail"]), token: z.string(),});// Example with the default INPUT prefix and process.env.parseInput(schema);// Example with the default INPUT prefix.parseInput(schema, undefined, { INPUT__MODE: "warn", INPUT__TOKEN: "secret-token",});// Example with a custom prefix (dot notation).parseInput(schema, "my.action", { MY__ACTION__MODE: "fail", MY__ACTION__TOKEN: "custom-token",});// Example with a custom prefix (path notation).parseInput(schema, "org/abc", { ORG__ABC__MODE: "fail", ORG__ABC__TOKEN: "custom-token",}); Copy
import { z } from "zod";import { parseInput } from "./parseInput";const schema = z.object({ mode: z.enum(["warn", "fail"]), token: z.string(),});// Example with the default INPUT prefix and process.env.parseInput(schema);// Example with the default INPUT prefix.parseInput(schema, undefined, { INPUT__MODE: "warn", INPUT__TOKEN: "secret-token",});// Example with a custom prefix (dot notation).parseInput(schema, "my.action", { MY__ACTION__MODE: "fail", MY__ACTION__TOKEN: "custom-token",});// Example with a custom prefix (path notation).parseInput(schema, "org/abc", { ORG__ABC__MODE: "fail", ORG__ABC__TOKEN: "custom-token",});
Zod schema type (typically z.ZodObject)
z.ZodObject
Zod schema defining the expected input shape and validation rules
Optional
Optional prefix for environment variables (default: "INPUT")
"INPUT"
Optional environment object (default: process.env)
process.env
Parsed and validated input object matching the schema type
ZodError if validation fails
Parses and validates GitHub Actions inputs against a Zod schema.
For each key in the schema, the function attempts to read the value from:
@actions/coregetInput)The first non-undefined value is used. Values are then validated and transformed according to the provided Zod schema.
Example