diff --git a/validation/.gitignore b/.gitignore similarity index 100% rename from validation/.gitignore rename to .gitignore diff --git a/README.md b/README.md index fd3868e..d9e3e1c 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,34 @@ # open-science-catalog-validation -Validation for [open-science-catalog-metadata](https://github.com/ESA-EarthCODE/open-science-catalog-metadata) +Validation for [open-science-catalog-metadata](https://github.com/ESA-EarthCODE/open-science-catalog-metadata). +# Instructions -## How-to +To run validation do the following: -In order to run the valdation, run the folling steps: +```bash +npm install ESA-EarthCODE/open-science-catalog-validation +``` + +Then, inside a folder containing a STAC structure compatible with Open Science Catalog, run: ```bash -npm install +open-science-catalog-validation ./{eo-missions,products,projects,themes,variables} ``` +Example for single file validation: + ```bash -npx stac-node-validator --config config.json ../../metadata/{eo-missions,products,projects,themes,variables} -``` \ No newline at end of file +open-science-catalog-validation ./projects/3d-earth/collection.json +``` + +# How it works +This validation package is based on [stac-node-validator](https://github.com/stac-utils/stac-node-validator). Additional to generic validation following the [STAC spec](https://github.com/radiantearth/stac-spec) it does some custom validation (see [./validate.js](./validate.js)). + +# Open Science Catalog STAC schema +Open Science Catalog requires a certain STAC structure for its entities (products, projects, variables etc.). The schema for these can be found in [./schemas](./schemas). + +These schemas can also be used for e.g. automatically rendering an input form. + +# Development +For development, copy some compatible folder structure into the root folder, then run `npm install` follwed by a `npm test`. + diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 0000000..496cc96 --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node +const { resolve } = require("path"); +const { exec } = require("child_process"); + +exec( + `npm explore open-science-catalog-validation -- npm run test -- ${process.argv + .slice(2) + .map((p) => resolve(p)) + .join(" ")}`, + (error, stdout) => { + if (error) { + console.error("Validation failed!"); + } else { + console.info("Validation successful!"); + } + console.log(stdout); + }, +); diff --git a/config.json b/config.json new file mode 100644 index 0000000..c0f64cf --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "lint": false, + "custom": "./validate.js" +} \ No newline at end of file diff --git a/validation/definitions.js b/definitions.js similarity index 100% rename from validation/definitions.js rename to definitions.js diff --git a/validation/package-lock.json b/package-lock.json similarity index 99% rename from validation/package-lock.json rename to package-lock.json index 8ba47b9..1094d66 100644 --- a/validation/package-lock.json +++ b/package-lock.json @@ -1,17 +1,20 @@ { - "name": "validation", - "version": "1.0.0", + "name": "open-science-catalog-validation", + "version": "1.0.0-rc.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "validation", - "version": "1.0.0", + "name": "open-science-catalog-validation", + "version": "1.0.0-rc.1", "license": "ISC", "dependencies": { "fs-extra": "^11.1.1", "image-size": "^1.0.2", "stac-node-validator": "2.0.0-beta.12" + }, + "bin": { + "open-science-catalog-validation": "bin/cli.js" } }, "node_modules/@jest/schemas": { diff --git a/validation/package.json b/package.json similarity index 75% rename from validation/package.json rename to package.json index f66d6d0..4587f57 100644 --- a/validation/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "validation", - "version": "1.0.0", + "name": "open-science-catalog-validation", + "version": "1.0.0-rc.1", "description": "Validates the metadata", "main": "validate.js", "author": "EOX", "license": "ISC", + "bin": "./bin/cli.js", "dependencies": { "fs-extra": "^11.1.1", "image-size": "^1.0.2", @@ -13,4 +14,4 @@ "scripts": { "test": "stac-node-validator --config config.json" } -} \ No newline at end of file +} diff --git a/validation/validate.js b/validate.js similarity index 94% rename from validation/validate.js rename to validate.js index 29eee5e..58485e9 100644 --- a/validation/validate.js +++ b/validate.js @@ -12,16 +12,6 @@ const { } = require('./definitions.js'); const BEFORE_BUILD = process.env.BUILD_STAGE !== 'after-build'; -const GITHUB_SCHEMA_URI = process.env.GITHUB_SCHEMA_URI || "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main"; - -if (!GITHUB_SCHEMA_URI) { - // GITHUB_SCHEMA_URI = "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/"; - // throw new Error("GITHUB_SCHEMA_URI environment variable is not set"); -} -else { - console.log(`Using schema URI: ${GITHUB_SCHEMA_URI}`); -} - class CustomValidator extends BaseValidator { constructor() { diff --git a/validation/README.md b/validation/README.md deleted file mode 100644 index cfccfee..0000000 --- a/validation/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Instructions - -To run validation you need the following folders: - -- `/.github/workflows/validation` -- `/schemas` - -The following commands can run the validation. - -Switch to this folder (if not done yet): - -```bash -cd .github/workflows/validation -``` - -Install dependencies: - -```bash -npm ci -``` - -Set the hosted location of the schemas. -The URL has usually the form `https://raw.githubusercontent.com/{github org}/{github repo}/{github branch}`. -For example: - -- Windows PowerShell: `$env:GITHUB_SCHEMA_URI="https://raw.githubusercontent.com/EOEPCA/open-science-catalog-metadata-testing/ui-schemas"` -- Linux/MacOS: `export GITHUB_SCHEMA_URI="https://raw.githubusercontent.com/EOEPCA/open-science-catalog-metadata-testing/ui-schemas"` - -Run the validator: - -```bash -npm test -``` diff --git a/validation/config.json b/validation/config.json deleted file mode 100644 index 50b1e59..0000000 --- a/validation/config.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "lint": false, - "custom": "./validate.js", - "schemaMap": { - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/catalog.json": "../schemas/catalog.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/collection.json": "../schemas/collection.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/contacts.json": "../schemas/contacts.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/eo-missions/children.json": "../schemas/eo-missions/children.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/eo-missions/parent.json": "../schemas/eo-missions/parent.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/processes/parent.json": "../schemas/processes/parent.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/products/children.json": "../schemas/products/children.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/products/parent.json": "../schemas/products/parent.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/projects/children.json": "../schemas/projects/children.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/projects/parent.json": "../schemas/projects/parent.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/themes/children.json": "../schemas/themes/children.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/themes/parent.json": "../schemas/themes/parent.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/variables/children.json": "../schemas/variables/children.json", - "https://raw.githubusercontent.com/ESA-EarthCODE/open-science-catalog-metadata-validation/main/schemas/variables/parent.json": "../schemas/variables/parent.json" - } -} \ No newline at end of file