Skip to content

Commit

Permalink
FAB-3676 add check_license
Browse files Browse the repository at this point in the history
Change-Id: Ibb4bbd088bd1e7409e39825f9256a95509e2a751
Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
  • Loading branch information
christo4ferris authored and ryjones committed Apr 7, 2018
1 parent 5aeda42 commit d85d349
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build/tasks/chklic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

const gulp = require('gulp');
const shell = require('gulp-shell');

gulp.task('check_license', shell.task('./scripts/check_license.sh'));
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ var gulp = require('gulp');
// Require all tasks in gulp/tasks, including subfolders
requireDir('./build/tasks', { recurse: true });

gulp.task('default', ['lint'], function () {
gulp.task('default', ['lint', 'check_license'], function () {
// This will only run if the lint task is successful...
});
63 changes: 63 additions & 0 deletions scripts/check_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

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 "\.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$" \
| sort -u`
}

CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
filterExcludedFiles
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
fi

if [[ -z "$CHECK" ]]; 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"`
if [[ -z "$missing" ]]; then
echo "All files have SPDX-License-Identifier headers"
exit 0
fi
echo "The following files are missing SPDX-License-Identifier headers:"
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 d85d349

Please sign in to comment.