Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit d85d349

Browse files
christo4ferrisryjones
authored andcommitted
FAB-3676 add check_license
Change-Id: Ibb4bbd088bd1e7409e39825f9256a95509e2a751 Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
1 parent 5aeda42 commit d85d349

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

build/tasks/chklic.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
const gulp = require('gulp');
4+
const shell = require('gulp-shell');
5+
6+
gulp.task('check_license', shell.task('./scripts/check_license.sh'));

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ var gulp = require('gulp');
99
// Require all tasks in gulp/tasks, including subfolders
1010
requireDir('./build/tasks', { recurse: true });
1111

12-
gulp.task('default', ['lint'], function () {
12+
gulp.task('default', ['lint', 'check_license'], function () {
1313
// This will only run if the lint task is successful...
1414
});

scripts/check_license.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
function filterExcludedFiles {
9+
CHECK=`echo "$CHECK" \
10+
| grep -v "^\.git/" \
11+
| grep -v "^\.build/" \
12+
| grep -v "^vendor/" \
13+
| grep -v "testdata/" \
14+
| grep -v "^LICENSE$" \
15+
| grep -v "\.png$" \
16+
| grep -v "\.rst$" \
17+
| grep -v "\.pem$" \
18+
| grep -v "\.block$" \
19+
| grep -v "\.tx$" \
20+
| grep -v "_sk$" \
21+
| grep -v "\.key$" \
22+
| grep -v "\.gen\.go$" \
23+
| grep -v "^Gopkg\.lock$" \
24+
| grep -v "\.md$" \
25+
| grep -v "\.pb\.go$" \
26+
| sort -u`
27+
}
28+
29+
CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
30+
filterExcludedFiles
31+
if [[ -z "$CHECK" ]]; then
32+
LAST_COMMITS=($(git log -2 --pretty=format:"%h"))
33+
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r ${LAST_COMMITS[1]} ${LAST_COMMITS[0]})
34+
filterExcludedFiles
35+
fi
36+
37+
if [[ -z "$CHECK" ]]; then
38+
echo "All files are excluded from having license headers"
39+
exit 0
40+
fi
41+
42+
missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier"`
43+
if [[ -z "$missing" ]]; then
44+
echo "All files have SPDX-License-Identifier headers"
45+
exit 0
46+
fi
47+
echo "The following files are missing SPDX-License-Identifier headers:"
48+
echo "$missing"
49+
echo
50+
echo "Please replace the Apache license header comment text with:"
51+
echo "SPDX-License-Identifier: Apache-2.0"
52+
53+
echo
54+
echo "Checking committed files for traditional Apache License headers ..."
55+
missing=`echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0"`
56+
if [[ -z "$missing" ]]; then
57+
echo "All remaining files have Apache 2.0 headers"
58+
exit 0
59+
fi
60+
echo "The following files are missing traditional Apache 2.0 headers:"
61+
echo "$missing"
62+
echo "Fatal Error - All files must have a license header"
63+
exit 1

0 commit comments

Comments
 (0)