github.com/hyperledger/aries-framework-go@v0.3.2/scripts/check_license.sh (about) 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 echo "Running $0" 9 10 function filterExcludedFiles { 11 CHECK=`echo "$CHECK" | grep -v .png$ | grep -v .rst$ | grep -v ^.git/ \ 12 | grep -v .pem$ | grep -v .block$ | grep -v .tx$ | grep -v ^LICENSE$ | grep -v _sk$ \ 13 | grep -v .key$ | grep -v .crt$ | grep -v \\.gen.go$ | grep -v \\.json$ | grep -v Gopkg.lock$ \ 14 | grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | grep -v ci.properties$ \ 15 | grep -v go.sum$ | grep -v gomocks | grep -v \\.jsonld$ | grep -v testdata/ | grep -v third_party/ | sort -u` 16 } 17 18 CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD) 19 REMOTE_REF=$(git log -1 --pretty=format:"%d" | grep '[(].*\/' | wc -l) 20 21 # If CHECK is empty then there is no working directory changes: fallback to last two commits. 22 # Else if REMOTE_REF=0 then working copy commits are even with remote: only use the working copy changes. 23 # Otherwise assume that the change is amending the previous commit: use both last two commit and working copy changes. 24 if [[ -z "${CHECK}" ]] || [[ "${REMOTE_REF}" -eq 0 ]]; then 25 if [[ ! -z "${CHECK}" ]]; then 26 echo "Examining last commit and working directory changes" 27 CHECK+=$'\n' 28 else 29 echo "Examining last commit changes" 30 fi 31 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 else 35 echo "Examining working directory changes" 36 fi 37 38 filterExcludedFiles 39 40 if [[ -z "$CHECK" ]]; then 41 echo "All files are excluded from having license headers" 42 exit 0 43 fi 44 45 missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier"` 46 if [[ -z "$missing" ]]; then 47 echo "All files have SPDX-License-Identifier headers" 48 exit 0 49 fi 50 echo "The following files are missing SPDX-License-Identifier headers:" 51 echo "$missing" 52 echo 53 echo "Please replace the Apache license header comment text with:" 54 echo "SPDX-License-Identifier: Apache-2.0" 55 56 echo 57 echo "Checking committed files for traditional Apache License headers ..." 58 missing=`echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0"` 59 if [[ -z "$missing" ]]; then 60 echo "All remaining files have Apache 2.0 headers" 61 exit 0 62 fi 63 echo "The following files are missing traditional Apache 2.0 headers:" 64 echo "$missing" 65 echo "Fatal Error - All files must have a license header" 66 exit 1