Skip to content

Commit c26707e

Browse files
authored
Merge pull request #29 from cicsdev/aj-copyright
Copyright checker auto update
2 parents 80b50c5 + 3721bf9 commit c26707e

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.github/workflows/java.yaml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

cics-java-liberty-link-app/src/main/java/com/ibm/cics/server/examples/wlp/link/HelloLiberty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* */
33
/* SAMPLE */
44
/* */
5-
/* (c) Copyright IBM Corp. 2016 All Rights Reserved */
5+
/* (c) Copyright IBM Corp. 2016, 2024 All Rights Reserved */
66
/* */
77
/* US Government Users Restricted Rights - Use, duplication or */
88
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp */

0 commit comments

Comments
 (0)