2024-02-08 02:22:15 -08:00
|
|
|
import { getInput, error } from '@actions/core'
|
|
|
|
import * as yaml from 'yaml'
|
|
|
|
import { z, ZodError } from 'zod'
|
2020-05-09 20:01:25 +07:00
|
|
|
|
2024-02-08 02:22:15 -08:00
|
|
|
const RunInstallSchema = z.object({
|
|
|
|
recursive: z.boolean().optional(),
|
|
|
|
cwd: z.string().optional(),
|
|
|
|
args: z.array(z.string()).optional(),
|
|
|
|
})
|
2020-05-09 20:01:25 +07:00
|
|
|
|
2024-02-08 02:22:15 -08:00
|
|
|
const RunInstallInputSchema = z.union([
|
|
|
|
z.null(),
|
|
|
|
z.boolean(),
|
|
|
|
RunInstallSchema,
|
|
|
|
z.array(RunInstallSchema),
|
|
|
|
])
|
2020-05-09 20:01:25 +07:00
|
|
|
|
2024-02-08 02:22:15 -08:00
|
|
|
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}`)
|
2020-05-09 20:01:25 +07:00
|
|
|
|
2024-02-08 02:22:15 -08:00
|
|
|
if (exception instanceof ZodError) {
|
|
|
|
error(`Errors: ${exception.errors}`)
|
|
|
|
} else {
|
|
|
|
error(`Exception: ${exception}`)
|
2020-05-09 20:01:25 +07:00
|
|
|
}
|
2024-02-08 02:22:15 -08:00
|
|
|
process.exit(1)
|
2020-05-09 20:01:25 +07:00
|
|
|
}
|
|
|
|
}
|