github.com/zcqzcg/fabric-ca@v2.0.0-alpha.0.20200416163940-d878ee6db75a+incompatible/scripts/check_license (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  function filterGeneratedFiles {
     9      for f in $@; do
    10          head -n2 $f | grep -qE 'Code generated by.*DO NOT EDIT' || echo $f
    11      done
    12  }
    13  
    14  function filterExcludedFiles {
    15    CHECK=`echo "$CHECK" \
    16  		| grep -v "^\.git/" \
    17  		| grep -v "^\.build/" \
    18  		| grep -v "^vendor/" \
    19  		| grep -v "testdata/" \
    20  		| grep -v "swagger/" \
    21  		| grep -v "^LICENSE$" \
    22  		| grep -v "\.png$" \
    23  		| grep -v "\.rst$" \
    24  		| grep -v "\.txt$" \
    25  		| grep -v "\.pem$" \
    26  		| grep -v "_sk$" \
    27  		| grep -v "\.key$" \
    28  		| grep -v "\.gen\.go$" \
    29  		| grep -v "^Gopkg\.lock$" \
    30  		| grep -v "\.md$" \
    31  		| grep -v "\.pb\.go$" \
    32  		| grep -v ".gitignore" \
    33          | grep -v "\.xml$" \
    34  		| grep -v "\.mod$" \
    35  		| grep -v "\.sum" \
    36  		| sort -u`
    37  
    38    CHECK=$(filterGeneratedFiles "$CHECK")
    39  }
    40  
    41  CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
    42  filterExcludedFiles
    43  if [[ -z "$CHECK" ]]; then
    44    LAST_COMMITS=($(git log -2 --pretty=format:"%h"))
    45    CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r ${LAST_COMMITS[1]} ${LAST_COMMITS[0]})
    46    filterExcludedFiles
    47  fi
    48  
    49  if [[ -z "$CHECK" ]]; then
    50     echo "All files are excluded from having license headers"
    51     exit 0
    52  fi
    53  
    54  echo "Checking Go files for license headers ..."
    55  missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier"`
    56  if [[ -z "$missing" ]]; then
    57     echo "All files have SPDX-License-Identifier headers"
    58     exit 0
    59  fi
    60  echo "The following files are missing SPDX-License-Identifier headers:"
    61  echo "$missing"
    62  echo
    63  echo "Please replace the Apache license header comment text with:"
    64  echo "SPDX-License-Identifier: Apache-2.0"
    65  
    66  missing=`echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "Apache License"`
    67  if [ -z "$missing" ]; then
    68     echo "All remaining files have Apache 2.0 headers"
    69     exit 0
    70  fi
    71  
    72  echo "The following files are missing license headers:"
    73  echo "$missing"
    74  exit 1