fix: use zod.infer for exported RunInstall types

This commit is contained in:
Erik Burton 2024-02-05 10:51:28 -08:00
parent 2be3e926cc
commit e801474ba4
No known key found for this signature in database

View File

@ -2,37 +2,28 @@ import { getInput, error } from '@actions/core'
import * as yaml from 'yaml'
import { z, ZodError } from 'zod'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
const zRunInstall = z.object({
const RunInstallSchema = z.object({
recursive: z.boolean().optional(),
cwd: z.string().optional(),
args: z.array(z.string()).optional(),
})
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const zRunInstallInput = z.union([
const RunInstallInputSchema = z.union([
z.null(),
z.boolean(),
zRunInstall,
z.array(zRunInstall),
RunInstallSchema,
z.array(RunInstallSchema),
])
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
export type RunInstall = z.infer<typeof RunInstallSchema>
export function parseRunInstall(inputName: string): RunInstall[] {
const input = getInput(inputName, { required: true })
const parsedInput: unknown = yaml.parse(input)
try {
const result: RunInstallInput = zRunInstallInput.parse(parsedInput)
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result