From 2c263b91ded31aeb76a03314f2c5b8964aad8b4c Mon Sep 17 00:00:00 2001 From: Thanat0s Date: Sat, 25 Feb 2017 10:23:51 +0100 Subject: [PATCH 1/2] modify validators to check json an format, stop on any error --- jq_all_the_things.sh | 15 +++++++++++++-- validate_all.sh | 35 ++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/jq_all_the_things.sh b/jq_all_the_things.sh index 16e241e..2d9cc62 100755 --- a/jq_all_the_things.sh +++ b/jq_all_the_things.sh @@ -1,17 +1,28 @@ #!/bin/bash +# Seeds sponge, from moreutils + +#Validate all Jsons first +for dir in `find . -name "*.json"` +do + echo validating ${dir} + cat ${dir} | jq . >/dev/null + rc=$? + if [[ $rc != 0 ]]; then exit $rc; fi +done + set -e set -x -# Seeds sponge, from moreutils - for dir in clusters/*.json do + # Beautify it cat ${dir} | jq . | sponge ${dir} done for dir in galaxies/*.json do + # Beautify it cat ${dir} | jq . | sponge ${dir} done diff --git a/validate_all.sh b/validate_all.sh index bcf0640..455c64d 100755 --- a/validate_all.sh +++ b/validate_all.sh @@ -1,21 +1,34 @@ #!/bin/bash +# Check Jsons format, and beautify +./jq_all_the_things.sh +rc=$? +if [[ $rc != 0 ]]; then + exit $rc +fi + set -e set -x -./jq_all_the_things.sh - -diffs=`git status --porcelain | wc -l` - -if ! [ $diffs -eq 0 ]; then - echo "Please make sure you run ./jq_all_the_things.sh before commiting." - exit 1 -fi +# fixme to remove.. +# Not need anymore ow, jq stop upon error... +# diffs=`git status --porcelain | wc -l` +# +#if ! [ $diffs -eq 0 ]; then +# echo "Please make sure you run ./jq_all_the_things.sh before commiting." +# exit +#fi +# Validate schemas for dir in clusters/*.json do echo -n "${dir}: " jsonschema -i ${dir} schema_clusters.json + rc=$? + if [[ $rc != 0 ]]; then + echo "Error on ${dir}" + exit $rc + fi echo '' done @@ -23,6 +36,10 @@ for dir in galaxies/*.json do echo -n "${dir}: " jsonschema -i ${dir} schema_galaxies.json + rc=$? + if [[ $rc != 0 ]]; then + echo "Error on ${dir}" + exit $rc + fi echo '' done - From 3073877d105c4c10af26b104389f8ab721fe32e4 Mon Sep 17 00:00:00 2001 From: Thanat0s Date: Sun, 26 Feb 2017 03:16:41 +0100 Subject: [PATCH 2/2] block by default, but usable anyway with param --- validate_all.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/validate_all.sh b/validate_all.sh index 455c64d..31f47d7 100755 --- a/validate_all.sh +++ b/validate_all.sh @@ -1,5 +1,11 @@ #!/bin/bash +# This file launch all validation of the jsons and schemas +# By default, It stop on file not commited. + +# you could test with command ./validate_all.sh something + + # Check Jsons format, and beautify ./jq_all_the_things.sh rc=$? @@ -10,14 +16,13 @@ fi set -e set -x -# fixme to remove.. -# Not need anymore ow, jq stop upon error... -# diffs=`git status --porcelain | wc -l` -# -#if ! [ $diffs -eq 0 ]; then -# echo "Please make sure you run ./jq_all_the_things.sh before commiting." -# exit -#fi +diffs=`git status --porcelain | wc -l` +if ! [ $diffs -eq 0 ]; then + echo "Please make sure you run ./jq_all_the_things.sh before commiting." + if [ $# -eq 0 ]; then + exit 1 + fi +fi # Validate schemas for dir in clusters/*.json