From f1cadcec4e241d544a0dec3013224869d36cf189 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Mon, 5 Dec 2016 15:17:15 -0700 Subject: [PATCH] fix(Makefile): don't do license check on gitignored files This fixes the license check so it doesn't run on files that are gitignored. Also provides a faster implementation if 'ag' is installed. --- scripts/validate-license.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/validate-license.sh b/scripts/validate-license.sh index fe7ec481b..1a96e79b3 100755 --- a/scripts/validate-license.sh +++ b/scripts/validate-license.sh @@ -16,22 +16,32 @@ set -euo pipefail IFS=$'\n\t' +license='Licensed under the Apache License, Version 2.0' + find_files() { - find . -not \( \ + find . -type f -not \( \ \( \ -wholename './vendor' \ -o -wholename './pkg/proto' \ -o -wholename '*testdata*' \ \) -prune \ \) \ - \( -name '*.go' -o -name '*.sh' -o -name 'Dockerfile' \) + \( -name '*.go' -o -name '*.sh' -o -name 'Dockerfile' \) \ + -not \( -exec git check-ignore -q {}+ \; \) } -failed=($(find_files | xargs grep -L 'Licensed under the Apache License, Version 2.0 (the "License");')) -if (( ${#failed[@]} > 0 )); then - echo "Some source files are missing license headers." - for f in "${failed[@]}"; do - echo " $f" - done - exit 1 + +if type "ag" > /dev/null 2>&1 ; then + # ag automatically skips anything in .gitignore + ag -L "$license" --go --shell --ignore pkg/proto --ignore testdata --ignore completions.bash +else + failed=($(find_files | xargs grep -L "$license")) + if (( ${#failed[@]} > 0 )); then + echo "Some source files are missing license headers." + for f in "${failed[@]}"; do + echo " $f" + done + exit 1 + fi fi +