Skip to content

Commit

Permalink
7449: Add GitHub action to verify copyright year
Browse files Browse the repository at this point in the history
Reviewed-by: hirt, clanger
  • Loading branch information
aptmac committed Dec 1, 2023
1 parent 8dd7683 commit 51e952e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions scripts/checkcopyrightyear.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 51e952e

Please sign in to comment.