From c2cde6bb9c1a43a69a276a20ad083d88b6fa0693 Mon Sep 17 00:00:00 2001 From: Braxton Hall Date: Thu, 27 Oct 2022 00:45:28 -0700 Subject: Workflow (#56) * Make the people check more rigorous * Actually install ajv before trying to use it in an action * Automatically prettify people.json * Rename workflow step * Make sure correct branch is checked out * Use tabs--- bin/checkPeople.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'bin') diff --git a/bin/checkPeople.js b/bin/checkPeople.js index 3c564a4..877ba8f 100644 --- a/bin/checkPeople.js +++ b/bin/checkPeople.js @@ -1,4 +1,37 @@ const fs = require("fs"); +const Ajv = require("ajv"); + +const ajv = new Ajv(); + +const schema = { + type: "array", + uniqueItems: true, + minItems: 1, + items: { + type: "object", + required: ["name", "title", "entries"], + properties: { + github: {type: "string"}, + name: {type: "string"}, + title: {type: "string"}, + entries: { + type: "array", + uniqueItems: true, + minItems: 1, + items: { + type: "object", + required: ["name", "link"], + properties: { + name: {type: "string"}, + link: {type: "string"}, + }, + additionalProperties: false, + }, + }, + }, + additionalProperties: false, + }, +}; const PEOPLE_PATH = "./people.json"; @@ -33,4 +66,10 @@ for (const entry of person.entries) { } } +const validate = ajv.compile(schema); +if (!validate(people)) { + console.error(validate.errors); + throw "people.json does not conform to json schema"; +} + console.log("Checked!"); -- cgit v1.2.3-70-g09d2