remove usage of ts-schema-autogen

This commit is contained in:
Erik Burton 2024-01-23 13:10:31 -08:00
parent cd44942e14
commit 7b9ebc12e6
No known key found for this signature in database
4 changed files with 42 additions and 82 deletions

View File

@ -16,10 +16,9 @@
"ajv": "^8.12.0", "ajv": "^8.12.0",
"expand-tilde": "^2.0.2", "expand-tilde": "^2.0.2",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"js-yaml": "^4.1.0" "yaml": "^2.3.4"
}, },
"devDependencies": { "devDependencies": {
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.38.1",
"typescript": "^5.3.3" "typescript": "^5.3.3"
} }

View File

@ -1,21 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strict": true,
"target": "ES2018",
"lib": [
"ES2018",
"ES2019",
"ES2020",
"ESNext"
],
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true
},
"input": "run-install.ts",
"symbol": "RunInstallInput",
"output": "run-install-input.schema.json"
}
}

View File

@ -1,39 +0,0 @@
{
"anyOf": [
{
"$ref": "#/definitions/RunInstall"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/RunInstall"
}
},
{
"type": [
"null",
"boolean"
]
}
],
"definitions": {
"RunInstall": {
"type": "object",
"properties": {
"recursive": {
"type": "boolean"
},
"cwd": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}

View File

@ -1,8 +1,5 @@
import { getInput, error, InputOptions } from '@actions/core' import { getInput,InputOptions } from '@actions/core'
import Ajv from 'ajv' import { parse } from 'yaml'
import { load } from 'js-yaml'
import process from 'process'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall { export interface RunInstall {
readonly recursive?: boolean readonly recursive?: boolean
@ -21,19 +18,43 @@ const options: InputOptions = {
} }
export function parseRunInstall(name: string): RunInstall[] { export function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = load(getInput(name, options)) as any const input: any = parse(getInput(name, options))
const ajv = new Ajv({
allErrors: true, if (!input) return []
}) if (input === true) return [{ recursive: true }]
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) { validateRunInstallInput(input)
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`) if (Array.isArray(input)) return input
}
return process.exit(1) return input;
} }
if (!result) return []
if (result === true) return [{ recursive: true }] function validateRunInstallInput(input: any) {
if (Array.isArray(result)) return result if (Array.isArray(input)) {
return [result] for (const entry of input) {
validateRunInstallEntry(entry)
}
} else {
validateRunInstallEntry(input)
}
}
function validateRunInstallEntry(input: any) {
if (typeof input !== 'object') {
throw new Error('Invalid input for run_install')
}
if (input.recursive !== undefined && typeof input.recursive !== 'boolean') {
throw new Error('Invalid input for run_install.recursive')
}
if (input.cwd !== undefined && typeof input.cwd !== 'string') {
throw new Error('Invalid input for run_install.cwd')
}
if (input.args !== undefined && !Array.isArray(input.args)) {
throw new Error('Invalid input for run_install.args')
}
} }