Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML validator #12

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ In this case, the `<DIR>` is the campaign folder, which contains the deployments
The command `yarn xls2csv <FILE>` can be used to convert a XLSX file to CSV. On this case, each spreadsheet in the file will be exported to CSV, directly in the `campaigns` folder.

Example of XLSX file: https://docs.google.com/spreadsheets/d/17v-ZfeWoPZoCAVSs57Y3Q1gKUe6S49fZ8rC2KOO_myY/edit?usp=sharing

### YAML Schema

The file `campaigns-schema.yaml` describes the format used in the campaigns files.
34 changes: 34 additions & 0 deletions campaigns-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
deployments:
required: true
type: list
schema:
type: dict
schema:
name:
required: true
type: string
platforms:
required: true
type: list
schema:
type: dict
schema:
name:
required: true
type: string
tsv_format:
require: false
type: boolean
rename_as_ict:
require: false
type: boolean
process_as_ict:
require: false
type: boolean
coords_divisor:
require: false
type: integer
files:
required: true
type: list
1 change: 1 addition & 0 deletions task/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"meow": "^12.1.1",
"simplify-geojson": "^1.0.5",
"slugify": "^1.6.6",
"superstruct": "^1.0.4",
"xlsx": "^0.18.5",
"xml2js": "^0.6.2",
"yaml": "2.3.4"
Expand Down
38 changes: 38 additions & 0 deletions task/tests/validate-yaml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');
const path = require('path');
const {
array,
assert,
boolean,
number,
object,
optional,
string,
} = require('superstruct');
const { readCampaignYaml } = require('../src/utils');

const structure = array(
object({
name: string(),
platforms: array(
object({
name: string(),
tsv_format: optional(boolean()),
rename_as_ict: optional(boolean()),
process_as_ict: optional(boolean()),
coords_divisor: optional(number()),
files: array(string()),
})
),
})
);

test('YAML files should be valid', () => {
const campaigns = fs.readdirSync('../campaigns/');
campaigns
.filter((c) => fs.existsSync(path.join('../campaigns/', c, 'deployments.yaml')))
.forEach((c) => {
console.log(`Checking: ${c}`);
assert(readCampaignYaml(path.join('../campaigns/', c)), structure);
});
});
5 changes: 5 additions & 0 deletions task/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,11 @@ strnum@^1.0.5:
resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db"
integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==

superstruct@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-1.0.4.tgz#0adb99a7578bd2f1c526220da6571b2d485d91ca"
integrity sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ==

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down
Loading