Skip to content

Commit 61d5657

Browse files
authored
Move json schema into typescript code (#10)
* Move json schema moved into typescript code * Update contents of the dist directory --------- Co-authored-by: goruha <goruha@users.noreply.github.com>
1 parent b1e5677 commit 61d5657

File tree

5 files changed

+134
-68
lines changed

5 files changed

+134
-68
lines changed

config.schema.json

Lines changed: 0 additions & 59 deletions
This file was deleted.

dist/index.js

Lines changed: 72 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as core from "@actions/core";
77
import Ajv2020 from "ajv/dist/2020"
88
import * as yaml from 'js-yaml';
99
import * as tc from "@actions/tool-cache";
10+
import {schema} from './schema'
1011

1112
interface ToolInfo {
1213
owner: string;
@@ -41,13 +42,10 @@ export async function run() {
4142

4243
const ajv = new Ajv2020()
4344

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

47-
// load schema json file
48-
const schemaJson = JSON.parse(fs.readFileSync(schemaJsonFile, 'utf8'));
4947
// validate input json against schema json
50-
const isValid = ajv.validate(schemaJson, configJson);
48+
const isValid = ajv.validate(schema, configJson);
5149
if (! isValid) {
5250
throw new Error(
5351
ajv.errorsText()

src/schema.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
export const schema = {
2+
"type": "object",
3+
"additionalProperties": false,
4+
"unevaluatedProperties": false,
5+
"patternProperties": {
6+
"^(.*)/(.*)$": {
7+
"oneOf": [
8+
{
9+
"type": "string"
10+
},
11+
{
12+
"type": "object",
13+
"additionalProperties": false,
14+
"properties": {
15+
"skip": {
16+
"type": "boolean",
17+
"default": false
18+
},
19+
"tag": {
20+
"type": "string"
21+
},
22+
"platform": {
23+
"type": "string"
24+
},
25+
"arch": {
26+
"type": "string"
27+
},
28+
"extension": {
29+
"type": "string"
30+
},
31+
"extension-matching": {
32+
"type": "boolean",
33+
"default": false
34+
},
35+
"binaries-location": {
36+
"type": "string"
37+
},
38+
"rename-to": {
39+
"type": "string"
40+
},
41+
"chmod": {
42+
"oneOf": [
43+
{
44+
"type": "string"
45+
},
46+
{
47+
"type": "integer"
48+
}
49+
]
50+
}
51+
}
52+
},
53+
{
54+
"type": "null"
55+
}
56+
]
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)