|
| 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