mirror of
https://github.com/pnpm/action-setup.git
synced 2025-04-02 14:20:11 +08:00
* upgrade versions to latest * remove usage of ts-schema-autogen * fix: update pnpm sources * update build/output * use node20 * fix: run-install array output * fix: maintain behaviour for parseRunInstall, error messages * fix: another edge case for input.args * fix: use zod for input validation * fix: use zod.infer for exported RunInstall types * fix: remove @types/js-yaml --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { getInput, error } from '@actions/core'
|
|
import * as yaml from 'yaml'
|
|
import { z, ZodError } from 'zod'
|
|
|
|
const RunInstallSchema = z.object({
|
|
recursive: z.boolean().optional(),
|
|
cwd: z.string().optional(),
|
|
args: z.array(z.string()).optional(),
|
|
})
|
|
|
|
const RunInstallInputSchema = z.union([
|
|
z.null(),
|
|
z.boolean(),
|
|
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 = RunInstallInputSchema.parse(parsedInput)
|
|
if (!result) return []
|
|
if (result === true) return [{ recursive: true }]
|
|
if (Array.isArray(result)) return result
|
|
return [result]
|
|
} catch (exception: unknown) {
|
|
error(`Error for input "${inputName}" = ${input}`)
|
|
|
|
if (exception instanceof ZodError) {
|
|
error(`Errors: ${exception.errors}`)
|
|
} else {
|
|
error(`Exception: ${exception}`)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
}
|