Skip to content

Commit

Permalink
[FAB-5431] Adopt Go SDK's check_license.sh
Browse files Browse the repository at this point in the history
Per Troy's suggestion on FAB-5431, this changes
the check_license.sh script to the one used in the
Go SDK.
This version doesn't return an error if the SPDX Id
is not used but will return an error if no Apache license
is found.

Change-Id: I731b6b7e8a84aebb10052371de2c241867ae9f33
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
  • Loading branch information
lehors committed Sep 13, 2017
1 parent b02e9f4 commit cb12927
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions scripts/check_license.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

CHECK=$(git diff --name-only HEAD * | grep -v .png$ | grep -v .rst$ | grep -v .git \
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | grep -v .txt | sort -u)
function filterExcludedFiles {
CHECK=`echo "$CHECK" | grep -v .png$ | grep -v .rst$ | grep -v ^.git/ \
| grep -v .pem$ | grep -v .block$ | grep -v .tx$ | grep -v ^LICENSE$ | grep -v _sk$ \
| grep -v .key$ | grep -v \\.gen.go$ | grep -v ^Gopkg.lock$ \
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | sort -u`
}

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

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 .rst$ | grep -v .git \
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | grep -v .txt | sort -u)
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r $(git log -2 \
--pretty=format:"%h"))
filterExcludedFiles
fi

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

echo "Checking committed files for SPDX-License-Identifier headers ..."
missing=`echo $CHECK | xargs grep -L "SPDX-License-Identifier"`
if [ -z "$missing" ]; then
missing=`echo "$CHECK" | 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
fi
Expand All @@ -25,4 +36,15 @@ echo "$missing"
echo
echo "Please replace the Apache license header comment text with:"
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"`
if [[ -z "$missing" ]]; then
echo "All remaining files have Apache 2.0 headers"
exit 0
fi
echo "The following files are missing traditional Apache 2.0 headers:"
echo "$missing"
echo "Fatal Error - All files must have a license header"
exit 1

0 comments on commit cb12927

Please sign in to comment.