Skip to content

Commit

Permalink
Move json schema into typescript code (#10)
Browse files Browse the repository at this point in the history
* Move json schema moved into typescript code

* Update contents of the dist directory

---------

Co-authored-by: goruha <[email protected]>
  • Loading branch information
goruha and goruha authored Aug 16, 2024
1 parent b1e5677 commit 61d5657
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 68 deletions.
59 changes: 0 additions & 59 deletions config.schema.json

This file was deleted.

76 changes: 72 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as core from "@actions/core";
import Ajv2020 from "ajv/dist/2020"
import * as yaml from 'js-yaml';
import * as tc from "@actions/tool-cache";
import {schema} from './schema'

interface ToolInfo {
owner: string;
Expand Down Expand Up @@ -41,13 +42,10 @@ export async function run() {

const ajv = new Ajv2020()

const schemaJsonFile = path.join(process.env['GITHUB_ACTION_PATH'] || "", 'config.schema.json')
const configJson = yaml.load(config);

// load schema json file
const schemaJson = JSON.parse(fs.readFileSync(schemaJsonFile, 'utf8'));
// validate input json against schema json
const isValid = ajv.validate(schemaJson, configJson);
const isValid = ajv.validate(schema, configJson);
if (! isValid) {
throw new Error(
ajv.errorsText()
Expand Down
59 changes: 59 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export const schema = {
"type": "object",
"additionalProperties": false,
"unevaluatedProperties": false,
"patternProperties": {
"^(.*)/(.*)$": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"skip": {
"type": "boolean",
"default": false
},
"tag": {
"type": "string"
},
"platform": {
"type": "string"
},
"arch": {
"type": "string"
},
"extension": {
"type": "string"
},
"extension-matching": {
"type": "boolean",
"default": false
},
"binaries-location": {
"type": "string"
},
"rename-to": {
"type": "string"
},
"chmod": {
"oneOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
}
},
{
"type": "null"
}
]
}
}
}

0 comments on commit 61d5657

Please sign in to comment.