Skip to content

Commit 255b2f6

Browse files
committed
test
1 parent 80b50c5 commit 255b2f6

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

.github/workflows/java.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,34 @@ jobs:
1919
EXTENSIONS: "*.java"
2020
COPYRIGHT_STATEMENT: "/**\n * Copyright IBM Corp. 2016\n */"
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+
echo "$CURRENT_COPYRIGHT"
34+
35+
# Check if LAST_MODIFIED_YEAR is anywhere in current copyright
36+
if [[ "$CURRENT_COPYRIGHT" != *"$LAST_MODIFIED_YEAR"* ]]; then
37+
# Check if copyright has two years
38+
if [[ "$CURRENT_COPYRIGHT" =~ ,\ [0-9]{4}$ ]]; then
39+
# If there is already a second year, replace it
40+
sed -i "s/$BASE_COPYRIGHT, [0-9]\{4\}/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
41+
else
42+
# If there is no second year, add it
43+
sed -i "s/$BASE_COPYRIGHT/$BASE_COPYRIGHT, $LAST_MODIFIED_YEAR/" "$file"
44+
fi
45+
fi
46+
fi
47+
done
2848
done
49+
2950
- name: Create Pull Request
3051
uses: peter-evans/create-pull-request@v7
3152
with:

0 commit comments

Comments
 (0)