Move run-install to its own module

This commit is contained in:
khai96_
2020-05-09 20:01:25 +07:00
parent 91d3d73121
commit 6fe65dc1af
4 changed files with 44 additions and 38 deletions

View File

@@ -1,21 +1,6 @@
import process from 'process'
import { getInput, error, InputOptions } from '@actions/core'
import { getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { safeLoad } from 'js-yaml'
import Ajv from 'ajv'
import runInstallSchema from './run-install-input.schema.json'
interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
@@ -31,25 +16,6 @@ const options: InputOptions = {
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = safeLoad(getInput(name, options))
const ajv = new Ajv({
allErrors: true,
async: false,
})
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]
}
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: parseInputPath('dest'),