-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI/CD script to detect out of date copyrights
Fix #2535. Signed-off-by: Steven Bellock <[email protected]>
- Loading branch information
1 parent
a1a59c5
commit e03f7c3
Showing
2 changed files
with
49 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
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,34 @@ | ||
#!/bin/bash | ||
|
||
# Check if the modified files' copyright dates are current. | ||
|
||
set -e | ||
|
||
# Change directory to top of repository. | ||
cd `dirname $0` | ||
cd ../ | ||
|
||
# Get list of changed files. | ||
git fetch origin main | ||
modified_files=$(git diff --name-only --diff-filter=AM origin/main..HEAD) | ||
|
||
current_year=$(date +%Y) | ||
exit_code=0 | ||
|
||
echo | ||
|
||
for file in $modified_files | ||
do | ||
# Only examine C files for now. | ||
if [[ $file == "include/"* ]] || [[ $file == "library/"* ]]; then | ||
if [[ $file == *".h" ]] || [[ $file == *".c" ]]; then | ||
# Assume that the copyright is located at the third line of the file. | ||
if [[ $(sed -n '3p' $file) != *$current_year* ]]; then | ||
echo $file needs to be updated with $current_year copyright. | ||
exit_code=1 | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
exit $exit_code |