From 8ff0c1c74b0a5768a459c5b121557eb17403b9ac Mon Sep 17 00:00:00 2001 From: Cyprian Laskowski Date: Wed, 22 Jan 2020 22:41:20 +0100 Subject: [PATCH] IssueID #1104: created script and pre-commit hook for automatic example validation --- scripts/install_git_hooks | 6 ++++++ scripts/validate_examples | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 scripts/install_git_hooks create mode 100755 scripts/validate_examples diff --git a/scripts/install_git_hooks b/scripts/install_git_hooks new file mode 100755 index 0000000..7eb145b --- /dev/null +++ b/scripts/install_git_hooks @@ -0,0 +1,6 @@ +#!/bin/bash + +top_dir=`git rev-parse --show-toplevel` +cd $top_dir/.git/hooks +ln -s ../../scripts/validate_examples pre-commit + diff --git a/scripts/validate_examples b/scripts/validate_examples new file mode 100755 index 0000000..b4c0726 --- /dev/null +++ b/scripts/validate_examples @@ -0,0 +1,23 @@ +#!/bin/bash + +branch=`git rev-parse --abbrev-ref HEAD` +script_dir="$(dirname "$(readlink -f "$0")")" +cd $script_dir +if [[ $branch == "master" ]]; then + schema_dir=../resources/schema + example_dir=../examples + for example_subdir in $example_dir/* + do + base=${example_subdir##*/} + schema=$schema_dir/$base.xsd + for example_file in $example_subdir/*.xml + do + command="xmllint -schema $schema $example_file --noout" + echo $command + if ! $command; then + exit 1 + fi + done + done +fi +exit 0