From 51e952e551591c258d732c8f4f22901fb18014a3 Mon Sep 17 00:00:00 2001 From: Alex Macdonald Date: Fri, 1 Dec 2023 22:30:09 +0000 Subject: [PATCH] 7449: Add GitHub action to verify copyright year Reviewed-by: hirt, clanger --- .github/workflows/validate.yml | 12 ++++++++++++ scripts/checkcopyrightyear.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 scripts/checkcopyrightyear.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f31991a321..f9757ace92 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -41,6 +41,18 @@ concurrency: cancel-in-progress: true jobs: + check_copyright_year: + runs-on: 'ubuntu-latest' + defaults: + run: + shell: bash + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name : Check latest copyright year + run: ./scripts/checkcopyrightyear.sh build_and_test: name: Build and Test on ${{ matrix.os }} strategy: diff --git a/scripts/checkcopyrightyear.sh b/scripts/checkcopyrightyear.sh new file mode 100755 index 0000000000..d5a1a3a0c7 --- /dev/null +++ b/scripts/checkcopyrightyear.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +CURRENT_YEAR=$(date +'%Y') +MODIFIED_FILES=$(git diff --name-only origin/master) +counter=0 + +for fileToCheck in $MODIFIED_FILES +do + if [[ ($fileToCheck =~ .*\.java) || ($fileToCheck =~ .*\.htm) || ($fileToCheck =~ pom.xml) || ($fileToCheck =~ .*\.properties) ]] + then + LATEST=$(sed -n "s/^.*Copyright (c).\+\(20[[:digit:]]\{2\}\).*$/\1/p" $fileToCheck) + for year in $LATEST; do + if [ $year -ne $CURRENT_YEAR ] + then + counter=$((counter + 1)) + echo "Requires update: $fileToCheck" + fi + done + fi +done +if [ $counter -ne 0 ] +then + echo "There is a total of $counter copyright year(s) that require updating." + exit 1 +else + exit 0 +fi