kolla/tools/pre-commit-hook
Swapnil Kulkarni (coolsvap) eb1bfc2c2e Add support to lint the install commands in Dockerfiles
Change-Id: Icb47ba8b13b13889e28bb285321f11344400edc2
Closes-Bug:#1582618
2016-05-26 17:41:42 +05:30

45 lines
855 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 "=== json checks ==="
${TOPLEVEL}/tools/validate-all-json.sh || RES=1
echo "=== dockerfile checks ==="
${TOPLEVEL}/tools/validate-all-dockerfiles || RES=1
exit $RES