-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aceefdb
commit 2569569
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Validate Vehicle Profiles | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
validate-vehicle-profiles: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
- run: | | ||
cd .vehicle_profiles | ||
npm ci | ||
npm run validate |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"title": "WiCan Vehicle Profile", | ||
"description": "Data about various models of cars and their settings", | ||
"type": "object", | ||
"properties": { | ||
"car_model": { | ||
"description": "Name of car model, should include Make and Model(s)", | ||
"type": "string" | ||
}, | ||
"init": { | ||
"description": "Init String, don't forget the final ;", | ||
"type": "string" | ||
}, | ||
"pids": { | ||
"description": "Array of PID's and their parameters", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"pid": { | ||
"description": "The PID for this group of parameters", | ||
"type": "string" | ||
}, | ||
"parameters": { | ||
"description": "Array of Parameters for this PID", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"description": "Used in MQTT JSON, no spaces", | ||
"type": "string" | ||
}, | ||
"expression": { | ||
"description": "Expression to calculate value", | ||
"type": "string" | ||
}, | ||
"unit": { | ||
"description": "Unit for this parameter", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ "car_model", "init", "pids"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Ajv from "ajv" | ||
import { readFile } from 'fs/promises'; | ||
import { glob } from 'glob' | ||
|
||
const ajv = new Ajv() | ||
const schema = JSON.parse(await readFile("schema.json", "utf-8")) | ||
const validate = ajv.compile(schema) | ||
|
||
const source_folder = '../vehicle_profiles'; | ||
const files = await glob(source_folder + '/**/*.json') | ||
|
||
let errors = 0; | ||
|
||
async function validate_profile(path){ | ||
let file = await readFile(path, "utf-8"); | ||
let data = JSON.parse(file); | ||
let valid = validate(data); | ||
if(valid) return | ||
|
||
console.log(path) | ||
console.log(validate.errors) | ||
errors++; | ||
} | ||
|
||
let promises = []; | ||
files.forEach(file => { | ||
promises.push(validate_profile(file)); | ||
}); | ||
|
||
await Promise.all(promises); | ||
|
||
if(errors > 0){ | ||
throw new Error('Validation issues found, see log for details'); | ||
} |