mirror of
https://code.forgejo.org/pnpm/action-setup.git
synced 2025-05-17 20:34:44 +00:00
Use ajv to validate schema
This commit is contained in:
parent
bb24f595c2
commit
e373fffa0a
5 changed files with 29 additions and 9 deletions
|
@ -1,6 +1,9 @@
|
|||
import { getInput, InputOptions } from '@actions/core'
|
||||
import process from 'process'
|
||||
import { getInput, error, 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
|
||||
|
@ -30,6 +33,17 @@ 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(`${errorItem.dataPath}: ${errorItem.message}`)
|
||||
}
|
||||
return process.exit(1)
|
||||
}
|
||||
if (!result) return []
|
||||
if (result === true) return [{ recursive: true }]
|
||||
if (Array.isArray(result)) return result
|
||||
|
|
|
@ -3,7 +3,16 @@
|
|||
"instruction": {
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
"target": "ES2018",
|
||||
"lib": [
|
||||
"ES2018",
|
||||
"ES2019",
|
||||
"ES2020",
|
||||
"ESNext"
|
||||
],
|
||||
"moduleResolution": "Node",
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"input": "index.ts",
|
||||
"symbol": "RunInstallInput",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue