Skip to content

Commit

Permalink
Merge "[FAB-15316] Shellcheck script improvements"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed May 24, 2019
2 parents 3202494 + 8379122 commit a115763
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
75 changes: 39 additions & 36 deletions scripts/check_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,55 @@
# SPDX-License-Identifier: Apache-2.0
#

function filterGeneratedFiles {
for f in $@; do
head -n2 $f | grep -qE '// Code generated by' || echo $f
done
}
function filterExcludedAndGeneratedFiles {
excluded_files=(
'\.block$'
'^\.build/'
'ci\.properties'
'^\.git/'
'\.gen\.go$'
'^Gopkg\.lock$'
'\.key$'
'^LICENSE$'
'\.md$'
'\.pb\.go$'
'\.pem$'
'\.png$'
'\.pptx$'
'\.rst$'
'_sk$'
'\.tx$'
'\.txt$'
'testdata\/'
'^vendor\/'
)

local filter
filter=$(local IFS='|' ; echo "${excluded_files[*]}")

function filterExcludedFiles {
CHECK=`echo "$CHECK" \
| grep -v "^\.git/" \
| grep -v "^\.build/" \
| grep -v "^vendor/" \
| grep -v "testdata/" \
| grep -v "^LICENSE$" \
| grep -v "\.png$" \
| grep -v "\.rst$" \
| grep -v "\.txt$" \
| grep -v "\.pem$" \
| grep -v "\.block$" \
| grep -v "\.tx$" \
| grep -v "_sk$" \
| grep -v "\.key$" \
| grep -v "\.gen\.go$" \
| grep -v "^Gopkg\.lock$" \
| grep -v "\.md$" \
| grep -v "\.pb\.go$" \
| grep -v "\.pptx$" \
| grep -v "ci.properties" \
| sort -u`
read -ra files <<<"$@"
for f in "${files[@]}"; do
file=$(echo "$f" | grep -Ev "$filter" | sort -u)

CHECK=$(filterGeneratedFiles "$CHECK")
if [ -n "$file" ]; then
head -n2 "$file" | grep -qE '// Code generated by' || echo "$file"
fi
done
}

CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
filterExcludedFiles
CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | tr '\n' ' ')
if [[ -z "$CHECK" ]]; then
LAST_COMMITS=($(git log -2 --pretty=format:"%h"))
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r ${LAST_COMMITS[1]} ${LAST_COMMITS[0]})
filterExcludedFiles
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r "HEAD^..HEAD" | tr '\n' ' ')
fi

if [[ -z "$CHECK" ]]; then
FILTERED=$(filterExcludedAndGeneratedFiles "$CHECK")

if [[ -z "$FILTERED" ]]; then
echo "All files are excluded from having license headers"
exit 0
fi

missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier"`
missing=$(echo "$FILTERED" | sort -u | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier")
if [[ -z "$missing" ]]; then
echo "All files have SPDX-License-Identifier headers"
exit 0
Expand All @@ -63,7 +66,7 @@ echo "SPDX-License-Identifier: Apache-2.0"

echo
echo "Checking committed files for traditional Apache License headers ..."
missing=`echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0"`
missing=$(echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0")
if [[ -z "$missing" ]]; then
echo "All remaining files have Apache 2.0 headers"
exit 0
Expand Down
15 changes: 9 additions & 6 deletions scripts/check_spelling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
# SPDX-License-Identifier: Apache-2.0
#

CHECK=$(git diff --name-only HEAD * | grep -v .png$ | grep -v .git | grep -v ^CHANGELOG \
| grep -v ^vendor/ | grep -v ^build/ | sort -u)
filter() {
while read -r data; do
grep -Ev '^CHANGELOG|\.git|\.png$|^vendor/' <<< "$data"
done
}

CHECK=$(git diff --name-only HEAD -- * | filter)

if [[ -z "$CHECK" ]]; then
CHECK=$(git diff-tree --no-commit-id --name-only -r $(git log -2 \
--pretty=format:"%h") | grep -v .png$ | grep -v .git | grep -v ^CHANGELOG \
| grep -v ^vendor/ | grep -v ^build/ | sort -u)
CHECK=$(git diff-tree --no-commit-id --name-only -r HEAD^..HEAD | filter)
fi

echo "Checking changed go files for spelling errors ..."
errs=`echo $CHECK | xargs misspell -source=text`
errs=$(echo "$CHECK" | xargs misspell -source=text)
if [ -z "$errs" ]; then
echo "spell checker passed"
exit 0
Expand Down

0 comments on commit a115763

Please sign in to comment.