github.com/verrazzano/verrazzano@v1.7.0/tools/copyright/README.md (about)

     1  # Copyright Scanner
     2  
     3  This tool enforces that all required files have the necessary copyright and license 
     4  statements near the beginning of the file.
     5  
     6  ## Usage
     7  
     8  ```shell
     9  go run copyright.go [options] path [path ... ]
    10  
    11  Options:
    12  --enforce-current   Enforce that files provided to the tool have the current year in the copyright
    13  --verbose           Verbose output
    14  ```
    15  
    16  ## Running the Scanner
    17  
    18  The tool can be run simply by invoking it with a list of files or directory paths.
    19  
    20  For example, to check all files in the Verrazzano repo, you can run it as follows:
    21  
    22  ```shell
    23  $ cd ${VERRAZZANO_ROOT}
    24  $ go run copyright.go .
    25  Files to ignore: [platform-operator/scripts/install/config/cert-manager.crds.patch platform-operator/helm_config/charts/verrazzano/NOTES.txt platform-operator/helm_config/charts/verrazzano-application-operator/NOTES.txt LICENSES-OLCNE.pdf application-operator/deploy/application-operator.txt tests/e2e/config/scripts/terraform/cluster/required-env-vars tests/e2e/config/scripts/looping-test/types.txt .DS_Store]
    26  Directories to ignore: [platform-operator/thirdparty .idea]
    27  
    28  Copyright scanning target .
    29  
    30  Results of scan:
    31  	Files analyzed: 547
    32  	Files with error: 0
    33  	Files skipped: 50
    34  	Directories skipped: 9
    35  ```
    36  
    37  Adding `--verbose` will spit out more details.  For example:
    38  
    39  ```shell
    40  $ go run tools/copyright/copyright.go --verbose platform-operator/scripts 
    41  Files to ignore: [platform-operator/scripts/install/config/cert-manager.crds.patch platform-operator/helm_config/charts/verrazzano/NOTES.txt platform-operator/helm_config/charts/verrazzano-application-operator/NOTES.txt LICENSES-OLCNE.pdf application-operator/deploy/application-operator.txt tests/e2e/config/scripts/terraform/cluster/required-env-vars tests/e2e/config/scripts/looping-test/types.txt]
    42  Directories to ignore: [platform-operator/thirdparty]
    43  
    44  Copyright scanning target platform-operator/scripts
    45  Scanning platform-operator/scripts/install/1-install-istio.sh
    46  Scanning platform-operator/scripts/install/2-install-system-components.sh
    47  Scanning platform-operator/scripts/install/3-install-verrazzano.sh
    48  Scanning platform-operator/scripts/install/4-install-keycloak.sh
    49  Scanning platform-operator/scripts/install/common.sh
    50  Skipping file platform-operator/scripts/install/config/cert-manager.crds.patch
    51  Skipping file platform-operator/scripts/install/config/config_defaults.json
    52  Skipping file platform-operator/scripts/install/config/config_kind.json
    53  Skipping file platform-operator/scripts/install/config/config_oci.json
    54  Skipping file platform-operator/scripts/install/config/config_olcne.json
    55  Scanning platform-operator/scripts/install/config/coredns-template.yaml
    56  Scanning platform-operator/scripts/install/config/istio_intermediate_ca_config.txt
    57  Scanning platform-operator/scripts/install/config/istio_root_ca_config.txt
    58  Skipping file platform-operator/scripts/install/config/keycloak.json
    59  Scanning platform-operator/scripts/install/config/verrazzano_admission_controller_ca_config.txt
    60  Scanning platform-operator/scripts/install/config/verrazzano_admission_controller_cert_config.txt
    61  Scanning platform-operator/scripts/install/config.sh
    62  Scanning platform-operator/scripts/install/create_oci_config_secret.sh
    63  Scanning platform-operator/scripts/install/install-oke.sh
    64  Scanning platform-operator/scripts/install/k8s-dump-objects.sh
    65  Scanning platform-operator/scripts/install/logging.sh
    66  Skipping file platform-operator/scripts/uninstall/README.md
    67  Skipping file platform-operator/scripts/uninstall/build/logs/uninstall-verrazzano.sh.log
    68  Scanning platform-operator/scripts/uninstall/uninstall-steps/0-uninstall-applications.sh
    69  Scanning platform-operator/scripts/uninstall/uninstall-steps/1-uninstall-istio.sh
    70  Scanning platform-operator/scripts/uninstall/uninstall-steps/2-uninstall-system-components.sh
    71  Scanning platform-operator/scripts/uninstall/uninstall-steps/3-uninstall-verrazzano.sh
    72  Scanning platform-operator/scripts/uninstall/uninstall-steps/4-uninstall-keycloak.sh
    73  Skipping file platform-operator/scripts/uninstall/uninstall-steps/build/logs/1-uninstall-istio.sh.log
    74  Skipping file platform-operator/scripts/uninstall/uninstall-steps/build/logs/2-uninstall-system-components.sh.log
    75  Skipping file platform-operator/scripts/uninstall/uninstall-steps/build/logs/3-uninstall-verrazzano.sh.log
    76  Skipping file platform-operator/scripts/uninstall/uninstall-steps/build/logs/4-uninstall-keycloak.sh.log
    77  Scanning platform-operator/scripts/uninstall/uninstall-utils.sh
    78  Scanning platform-operator/scripts/uninstall/uninstall-verrazzano.sh
    79  
    80  Results of scan:
    81  	Files analyzed: 22
    82  	Files with error: 0
    83  	Files skipped: 12
    84  	Directories skipped: 0
    85  ```
    86  ## Scanning Locally Modified Files
    87  
    88  While doing local development, in addition to adding copyright/license statements to new files, the copyright statements 
    89  in existing files may need to be updated to add the current year.  
    90  
    91  You can use the scanner to check if the files modified locally have the correct copyright/license information,
    92  including the current year, using the `--enforce-current` option.
    93  
    94  The following example uses the `git status --short` command to obtain a set of locally modified files and validate the
    95  copyright/licsense information:
    96  
    97  ```shell
    98  $ go run tools/copyright/copyright.go --verbose --enforce-current  $(git status --short | cut -c 4-)
    99  Enforcing current year in copyright string
   100  Files to ignore: [platform-operator/scripts/install/config/cert-manager.crds.patch platform-operator/helm_config/charts/verrazzano/NOTES.txt platform-operator/helm_config/charts/verrazzano-application-operator/NOTES.txt LICENSES-OLCNE.pdf application-operator/deploy/application-operator.txt tests/e2e/config/scripts/terraform/cluster/required-env-vars tests/e2e/config/scripts/looping-test/types.txt .DS_Store]
   101  Directories to ignore: [platform-operator/thirdparty .idea]
   102  
   103  Copyright scanning target ignore_copyright_check.txt
   104  Copyright scanning target tools/copyright/README.md
   105  Copyright scanning target .DS_Store
   106  Copyright scanning target platform-operator/run-vpo.sh
   107  
   108  Results of scan:
   109  	Files analyzed: 2
   110  	Files with error: 0
   111  	Files skipped: 2
   112  	Directories skipped: 0
   113  ```
   114  
   115  ## Scanning Files Changed in a Branch
   116  
   117  In combination with Git, you can use the tool to scan for files modified between branches.
   118  
   119  The following example compares the current working branch against master to get the set of modified files and feeds it
   120  to the scanner, and also checks for the current year in the copyright:
   121  
   122  ```shell
   123  $ go run tools/copyright/copyright.go --enforce-current $(git diff --name-only origin/master) 
   124  Enforcing current year in copyright string
   125  Files to ignore: [platform-operator/scripts/install/config/cert-manager.crds.patch platform-operator/helm_config/charts/verrazzano/NOTES.txt platform-operator/helm_config/charts/verrazzano-application-operator/NOTES.txt LICENSES-OLCNE.pdf application-operator/deploy/application-operator.txt tests/e2e/config/scripts/terraform/cluster/required-env-vars tests/e2e/config/scripts/looping-test/types.txt .DS_Store]
   126  Directories to ignore: [platform-operator/thirdparty .idea]
   127  
   128  Copyright scanning target Jenkinsfile
   129  Copyright scanning target Makefile
   130  Copyright scanning target tools/copyright/README.md
   131  Copyright scanning target tools/copyright/copyright.go
   132  
   133  Results of scan:
   134  	Files analyzed: 3
   135  	Files with error: 0
   136  	Files skipped: 1
   137  	Directories skipped: 0
   138  ```