-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pre-commit Copyright Check (#181)
* add auto copyright scripts Signed-off-by: YanxuanLiu <[email protected]> * add license head check Signed-off-by: YanxuanLiu <[email protected]> * change json path Signed-off-by: YanxuanLiu <[email protected]> * fix path Signed-off-by: YanxuanLiu <[email protected]> * change license config to regex Signed-off-by: YanxuanLiu <[email protected]> * add slash Signed-off-by: YanxuanLiu <[email protected]> * change back to license tt Signed-off-by: YanxuanLiu <[email protected]> * change license path Signed-off-by: YanxuanLiu <[email protected]> * file name Signed-off-by: YanxuanLiu <[email protected]> * change license content Signed-off-by: YanxuanLiu <[email protected]> * change license content Signed-off-by: YanxuanLiu <[email protected]> * add exclude for md Signed-off-by: YanxuanLiu <[email protected]> * change include and exclude Signed-off-by: YanxuanLiu <[email protected]> * exclude all md Signed-off-by: YanxuanLiu <[email protected]> * add python script Signed-off-by: YanxuanLiu <[email protected]> * add more excludes Signed-off-by: YanxuanLiu <[email protected]> --------- Signed-off-by: YanxuanLiu <[email protected]>
- Loading branch information
1 parent
e3cfd1c
commit df7fa26
Showing
5 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A license header check | ||
The tool checks if all files in the repo contain the license header. | ||
NOTE: this script is for github actions only, you should not use it anywhere else. | ||
""" | ||
import os | ||
import sys | ||
import glob | ||
from argparse import ArgumentParser | ||
|
||
# Configs of the license header check | ||
includes = ['**/*'] | ||
excludes = ['**/*.md', 'NOTICE', 'TPC EULA.txt', '**/*.patch'] | ||
LICENSE_PATTERN = "Licensed under the Apache License" | ||
|
||
def filterFiles(repo_path): | ||
files = [] | ||
files_excluded = [] | ||
os.chdir(repo_path) | ||
for pattern in includes: | ||
files.extend([ f for f in glob.glob(repo_path + '/' + pattern, recursive=True) if os.path.isfile(f)]) | ||
for pattern in excludes: | ||
files_excluded.extend([ f for f in glob.glob(repo_path + '/' + pattern, recursive=True) if os.path.isfile(f)]) | ||
return list(set(files) - set(files_excluded)), list(set(files_excluded)) | ||
|
||
def checkLicenseHeader(files): | ||
no_license_files = [] | ||
for file in files: | ||
with open(file, 'r') as f: | ||
print("Checking file: {}".format(file)) | ||
content = f.read() | ||
if LICENSE_PATTERN not in content: | ||
no_license_files.append(file) | ||
return no_license_files | ||
|
||
if __name__ == '__main__': | ||
try: | ||
repo_path = '.' | ||
files, files_excluded = filterFiles(repo_path) | ||
no_license_files = checkLicenseHeader(files) | ||
warning_message = "" | ||
for file in files_excluded: | ||
warning_message += "WARNING: {} is excluded from this check.\n".format(file) | ||
print(warning_message) | ||
if no_license_files: | ||
error_message = "" | ||
for file in no_license_files: | ||
error_message += "ERROR: {} does not contain license header.\n".format(file) | ||
raise Exception(error_message) | ||
except Exception as e: | ||
print(e) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# A workflow to check license header of files | ||
|
||
name: Check License Headers | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
check-headers: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: license-check job | ||
run: | | ||
set -x | ||
python3 .github/workflows/license-check/license-check.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
repos: | ||
- repo: local | ||
hooks: | ||
- id: auto-copyrighter | ||
name: Update copyright year | ||
entry: scripts/auto-copyrighter.sh | ||
language: script | ||
pass_filenames: true | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER=${SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER:-OFF} | ||
|
||
case "$SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER" in | ||
|
||
OFF) | ||
echo "Copyright updater is DISABLED. Automatic Copyright Updater can be enabled/disabled by setting \ | ||
SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER=ON or SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER=OFF, \ | ||
correspondingly" | ||
exit 0 | ||
;; | ||
|
||
ON) | ||
;; | ||
|
||
*) | ||
echo "Invalid value of SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER=$SPARK_RAPIDS_BENCHMARKS_AUTO_COPYRIGHTER. | ||
Only ON or OFF are allowed" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
set -x | ||
echo "$@" | xargs -L1 sed -i -E \ | ||
"s/Copyright *\(c\) *([0-9,-]+)*-([0-9]{4}), *NVIDIA *CORPORATION/Copyright (c) \\1-`date +%Y`, NVIDIA CORPORATION/; /`date +%Y`/! s/Copyright *\(c\) ([0-9]{4}), *NVIDIA *CORPORATION/Copyright (c) \\1-`date +%Y`, NVIDIA CORPORATION/" |