@@ -17,14 +17,33 @@ jobs:
1717 - name : Check Copyright
1818 env :
1919 EXTENSIONS : " *.java"
20- COPYRIGHT_STATEMENT : " /** \n * Copyright IBM Corp. 2016\n */ "
20+ BASE_COPYRIGHT : " Copyright IBM Corp. 2016"
2121 run : |
22- for ext in $EXTENSIONS; do
23- for file in $(find . -type f -name "$ext" ! -path "cics-java-liberty-link-app/*"); do
24- if ! grep -q "Copyright" "$file"; then
25- echo -e "$COPYRIGHT_STATEMENT\n$(cat "$file")" > "$file"
26- fi
27- done
22+ for ext in "$EXTENSIONS"; do
23+ for file in $(find . -type f -name "$ext" -path "./cics-java-liberty-link-app/*"); do
24+ echo "Processing file: $file"
25+
26+ LAST_MODIFIED_YEAR=$(git log --follow -1 --format="%ad" --date=format:"%Y" -- "$file")
27+
28+ if ! grep -q "Copyright" "$file"; then
29+ echo -e "/**\n * $BASE_COPYRIGHT\n */\n$(cat "$file")" > "$file"
30+ else
31+ # Extract existing copyright line
32+ CURRENT_COPYRIGHT=$(grep -o "Copyright IBM Corp. [0-9]\{4\}\(, [0-9]\{4\}\)\?" "$file")
33+
34+ # Check if LAST_MODIFIED_YEAR is anywhere in current copyright
35+ if [[ "$CURRENT_COPYRIGHT" != *"$LAST_MODIFIED_YEAR"* ]]; then
36+ # Check if copyright has two years
37+ if [[ "$CURRENT_COPYRIGHT" =~ ,\ [0-9]{4}$ ]]; then
38+ # If there is already a second year, replace it
39+ sed -i "s/$BASE_COPYRIGHT, [0-9]\{4\}/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
40+ else
41+ # If there is no second year, add it
42+ sed -i "s/$BASE_COPYRIGHT/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
43+ fi
44+ fi
45+ fi
46+ done
2847 done
2948 - name : Create Pull Request
3049 uses : peter-evans/create-pull-request@v7
0 commit comments