Skip to content

Commit 48143b3

Browse files
committed
add gh actions to validate projects
1 parent 09e8549 commit 48143b3

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: JSON validation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
master
7+
paths:
8+
- 'projects/*.json'
9+
10+
jobs:
11+
validate:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Install dependencies
19+
run: npm install
20+
21+
- name: Validate JSON files
22+
run: npm run validate

package-lock.json

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

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@stricahq/cardano-contracts-registry",
3+
"version": "1.0.0",
4+
"description": "An off-chain registry to maintain labels, audits, and metadata for the dApps on Cardano",
5+
"scripts": {
6+
"validate": "node scripts/validate"
7+
},
8+
"author": "Strica",
9+
"license": "Apache-2.0",
10+
"dependencies": {
11+
"@joi/date": "^2.1.0",
12+
"joi": "^17.9.1"
13+
}
14+
}

scripts/validate.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const Joi = require("joi").extend(require("@joi/date"));
2+
const fs = require("fs");
3+
4+
const auditSchema = Joi.object({
5+
provider: Joi.string().required(),
6+
report: Joi.string().required(),
7+
date: Joi.date().format("DD-MM-YYYY").required(),
8+
});
9+
10+
const contractSchema = Joi.object({
11+
name: Joi.string().max(20).required(),
12+
version: Joi.number().required(),
13+
language: Joi.string().valid("PLUTUS", "NATIVESCRIPT").required(),
14+
languageVersion: Joi.number().required(),
15+
scriptHash: Joi.string().length(56).required(),
16+
github: Joi.string().max(80),
17+
description: Joi.string().max(140),
18+
audit: Joi.array().items(auditSchema),
19+
});
20+
21+
const schema = Joi.object({
22+
projectName: Joi.string().max(30).required(),
23+
labelPrefix: Joi.string().max(16).required(),
24+
website: Joi.string().max(35),
25+
twitter: Joi.string().max(16),
26+
discord: Joi.string().max(40),
27+
category: Joi.string().valid(
28+
"DEX",
29+
"DEFI",
30+
"REALFI",
31+
"MARKETPLACE",
32+
"NFT",
33+
"GAMING",
34+
"TOKEN",
35+
"ORACLE"
36+
),
37+
description: Joi.string().max(140),
38+
contracts: Joi.array().items(contractSchema),
39+
});
40+
41+
const files = fs
42+
.readdirSync("./projects")
43+
.filter((file) => file.endsWith(".json"));
44+
45+
const errors = [];
46+
47+
for (const filePath of files) {
48+
const contents = fs.readFileSync(`./projects/${filePath}`, "utf8");
49+
const data = JSON.parse(contents);
50+
const result = schema.validate(data, { abortEarly: false });
51+
if (result.error) {
52+
const errs = result.error.details.map((detail) => detail.message);
53+
errors.push(...errs);
54+
console.log(`Validation failed for ${filePath}\n${errs.join("\n")}\n`);
55+
}
56+
}
57+
58+
if (errors.length) {
59+
process.exit(1);
60+
}

0 commit comments

Comments
 (0)