From a37ee362b6280a285db2438c95ff19fed3c9a48d Mon Sep 17 00:00:00 2001 From: Steven Bellock Date: Tue, 23 Jan 2024 16:45:28 -0800 Subject: [PATCH] Add CI/CD script to detect out of date copyrights Fix #2535. Signed-off-by: Steven Bellock --- .github/workflows/compliance-checks.yml | 15 +++++++++++ script/check_copyright_date.sh | 34 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 script/check_copyright_date.sh diff --git a/.github/workflows/compliance-checks.yml b/.github/workflows/compliance-checks.yml index 6cf51aa3d3b..fd3f29d4ffa 100644 --- a/.github/workflows/compliance-checks.yml +++ b/.github/workflows/compliance-checks.yml @@ -44,6 +44,7 @@ jobs: git diff exit 1 fi + file-encoding: name: File Encoding Check runs-on: ubuntu-latest @@ -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 diff --git a/script/check_copyright_date.sh b/script/check_copyright_date.sh new file mode 100755 index 00000000000..656c6ee7812 --- /dev/null +++ b/script/check_copyright_date.sh @@ -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