diff options
-rwxr-xr-x | scripts/pre-commit.sh | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 38894f4..bc7fb6e 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + if git rev-parse --verify HEAD >/dev/null 2>&1 then base=HEAD @@ -10,9 +12,22 @@ fi error=0 -# Validate new/modified YAML project files for i in $(git diff --cached --name-only --diff-filter=AM $base -- "*yaml" | grep -vF .schema.yaml) do + # Generate unique key if missing + if ! grep -q ^key: "$i" + then + key=$(uuid) + while grep -qrw "$key" . + do + key=$(uuid) + done + echo "Generated key $key for $i" + sed -i "/^team:/akey: $key" "$i" + git add "$i" + fi + + # Validate new/modified YAML project files echo -n "Validating $i: " if ! scripts/validator "$i" then |