RoadieHQ / backstage-entity-validator

Validate properties and well known annotations in your Backstage catalog-info.yaml files.
https://roadie.io
68 stars 14 forks source link

Add CLI with support for validating multiple files #13

Closed joncfoo closed 3 years ago

joncfoo commented 3 years ago

Problem

The tool does not support validating multiple files at once.

Solution

Introduce a CLI that makes it possible to validate several files at once.

Notes

We first tried to wrap the invocation of this tool in a shell script, calling it once per file we needed to validate. With ~400 files it took ~6m30s to complete which felt too long.

We speculated that the bulk of the time being spent during a single execution was in the Ajv schema-validation compile phase. We hacked up a script to validate our suspicion and indeed found it to be true. We were able to validate ~400 files in ~6s; with the schema-validation compile happening once (It looks like Ajv caches compilation; calling it a second time is pretty fast).


The choice to use minimist was based on introducing the least number of dependencies.


There are two ways to provide files to validate:

  1. via CLI arguments
  2. via STDIN

We chose not to include a file-finder/globber as we felt that role was best left to other tools. e.g. via shell globbing validate-entity catalog/**/*.yaml, or piped input find ./catalog/ -name '*.yaml' -or -name '*.yml' | validate-entity -i


Validating several files at once produces a lot of output. To that end, a quiet option was introduced to control the verbosity of existing logging statements.


Care was taken to not introduce changes to the existing CLI interface which expects a single file to validate.


CLI usage:

❯ node src/index.js -h
Usage: validate-entity [OPTION] [FILE]

Validates Backstage entity definition files.  Files may be specified as
arguments or via STDIN, one per line.

OPTION:
-h  display help
-q  minimal output while validating entities
-i  validate files provided over standard input
Xantier commented 3 years ago

Thanks @joncfoo! That looks excellent and will be a good addition for this. Could you add few lines to the README file about this as well and I'll merge this in and release new versions.

joncfoo commented 3 years ago

🎉 I've updated the readme with the usage and examples.

Xantier commented 3 years ago

Thanks @joncfoo. This is now released as version 0.3.0