kolla/tools/pre-commit-hook
mnasiadka 712b258f2d Fix pre-commit-hook
Currently pre-commit-hook is failing due to yaml validations using
unversioned python and using non-existent json validations.

Change-Id: I67dc11efe667e2cc67ea1a731edc5c4a03ebd1e7
Closes-Bug: #1778146
2020-06-02 08:31:33 +00:00

41 lines
781 B
Bash
Executable File

#!/bin/bash
TOPLEVEL=$(git rev-parse --show-toplevel)
RES=0
cd $TOPLEVEL
if [ "$1" = "--install" ]; then
ln -sf ../../tools/pre-commit-hook .git/hooks/pre-commit
exit
fi
tmpdir=$(mktemp -d precommit.XXXXXX) || exit 1
trap "rm -rf $TOPLEVEL/$tmpdir" 0
git diff --cached --name-only --diff-filter=ACMR |
xargs git checkout-index --prefix=$tmpdir/ --
cd $tmpdir
echo "=== starting pre-commit checks ==="
echo "Checking the following files:"
find . -type f
echo "=== bashate checks ==="
files=$(egrep -rlI '^#!/(bin/|usr/bin/env )(ba)?sh' .)
[ "$files" ] && (bashate $files || RES=1)
echo "=== yaml checks ==="
${TOPLEVEL}/tools/validate-all-yaml.sh || RES=1
echo "=== dockerfile checks ==="
${TOPLEVEL}/tools/validate-all-dockerfiles.sh || RES=1
exit $RES