@@ -13,18 +13,41 @@ jobs:
1313 name : Check Copyright
1414 runs-on : ubuntu-latest
1515 steps :
16- - uses : actions/checkout@v3
16+ - name : Checkout repository
17+ uses : actions/checkout@v3
18+ with :
19+ fetch-depth : 0
20+
1721 - name : Check Copyright
1822 env :
1923 EXTENSIONS : " *.java"
20- COPYRIGHT_STATEMENT : " /** \n * Copyright IBM Corp. 2016\n */ "
24+ BASE_COPYRIGHT : " Copyright IBM Corp. 2016"
2125 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
26+ for ext in "$EXTENSIONS"; do
27+ for file in $(find . -type f -name "$ext" -path "./cics-java-liberty-link-app/*"); do
28+ echo "Processing file: $file"
29+
30+ LAST_MODIFIED_YEAR=$(git log --follow -1 --format="%ad" --date=format:"%Y" -- "$file")
31+
32+ if ! grep -q "Copyright" "$file"; then
33+ echo -e "/**\n * $BASE_COPYRIGHT\n */\n$(cat "$file")" > "$file"
34+ else
35+ # Extract existing copyright line
36+ CURRENT_COPYRIGHT=$(grep -o "Copyright IBM Corp. [0-9]\{4\}\(, [0-9]\{4\}\)\?" "$file")
37+
38+ # Check if LAST_MODIFIED_YEAR is anywhere in current copyright
39+ if [[ "$CURRENT_COPYRIGHT" != *"$LAST_MODIFIED_YEAR"* ]]; then
40+ # Check if copyright has two years
41+ if [[ "$CURRENT_COPYRIGHT" =~ ,\ [0-9]{4}$ ]]; then
42+ # If there is already a second year, replace it
43+ sed -i "s/$BASE_COPYRIGHT, [0-9]\{4\}/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
44+ else
45+ # If there is no second year, add it
46+ sed -i "s/$BASE_COPYRIGHT/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
47+ fi
48+ fi
49+ fi
50+ done
2851 done
2952 - name : Create Pull Request
3053 uses : peter-evans/create-pull-request@v7
0 commit comments