action-setup/src/inputs/run-install.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2020-05-09 21:01:25 +08:00
import process from 'process'
2021-03-23 12:43:49 +08:00
import { load } from 'js-yaml'
2020-05-09 21:01:25 +08:00
import Ajv from 'ajv'
import { getInput, error, InputOptions } from '@actions/core'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const options: InputOptions = {
required: true,
}
export function parseRunInstall(name: string): RunInstall[] {
2021-03-23 12:43:49 +08:00
const result: RunInstallInput = load(getInput(name, options)) as any
2020-05-09 21:01:25 +08:00
const ajv = new Ajv({
allErrors: true,
})
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) {
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
}
return process.exit(1)
}
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
}