KC's Workspace
    Preparing search index...

    Function parseInput

    • Parses and validates GitHub Actions inputs against a Zod schema.

      For each key in the schema, the function attempts to read the value from:

      1. Environment variables (via getEnv)
      2. GitHub Actions inputs (via @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",
      });

      Type Parameters

      Parameters

      • schema: S

        Zod schema defining the expected input shape and validation rules

      • Optionalprefix: string

        Optional prefix for environment variables (default: "INPUT")

      • Optionalenv: Readonly<ActionEnv>

        Optional environment object (default: process.env)

      Returns z.core.output<S>

      Parsed and validated input object matching the schema type

      ZodError if validation fails