Skip to content

Commit

Permalink
fix: use zod.infer for exported RunInstall types
Browse files Browse the repository at this point in the history
  • Loading branch information
erikburt committed Feb 5, 2024
1 parent 2be3e92 commit e801474
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/inputs/run-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e801474

Please sign in to comment.