Skip to content

Commit

Permalink
Add CI/CD script to detect out of date copyrights
Browse files Browse the repository at this point in the history
Fix #2535.

Signed-off-by: Steven Bellock <[email protected]>
  • Loading branch information
steven-bellock committed Jan 29, 2024
1 parent 33ed7e3 commit a37ee36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/compliance-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
git diff
exit 1
fi
file-encoding:
name: File Encoding Check
runs-on: ubuntu-latest
Expand All @@ -57,3 +58,17 @@ jobs:
if [ $? -ne 0 ]; then
exit 1
fi
copyright-date:
name: Check Copyright Year
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check
run: |
set +e
./script/check_copyright_date.sh
if [ $? -ne 0 ]; then
exit 1
fi
34 changes: 34 additions & 0 deletions script/check_copyright_date.sh
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

0 comments on commit a37ee36

Please sign in to comment.