Skip to content

Commit 64b8811

Browse files
committed
Update license action to update license checkstyle header if it exists
1 parent 8fdd72e commit 64b8811

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

‎.github/actions/update-license-headers/action.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ runs:
4949
git config user.name "${{ inputs.git-user-name }}"
5050
git config user.email "${{ inputs.git-user-email }}"
5151
52+
# Update checkstyle-header.txt files — committed separately
53+
echo "Scanning for checkstyle-header.txt files..."
54+
python3 "${{ github.action_path }}/update_checkstyle_header.py" .
55+
56+
git add .
57+
if ! git diff --cached --quiet; then
58+
git commit -m "Updating checkstyle header"
59+
echo "Checkstyle header committed."
60+
else
61+
echo "No checkstyle header changes to commit."
62+
fi
63+
5264
# Replace Apache License 2.0 headers across all source files
5365
echo "Scanning for Apache License headers..."
5466
python3 "${{ github.action_path }}/update_licenses.py" .
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Finds every checkstyle-header.txt in the repository and replaces its content
4+
with the Broadcom license header pattern for Checkstyle.
5+
"""
6+
7+
import os
8+
import sys
9+
10+
CHECKSTYLE_HEADER = (
11+
"^\\Q/*\\E$\n"
12+
"^\\Q * Copyright \u00a9 \\E20\\d\\d\\Q Broadcom Inc. and/or its subsidiaries. All Rights Reserved.\\E$\n"
13+
"^\\Q * Copyright \\E20\\d\\d\\-present\\Q the original author or authors.\\E$\n"
14+
"^\\Q */\\E$\n"
15+
"^$\n"
16+
"^.*$\n"
17+
)
18+
19+
SKIP_DIRS = frozenset([
20+
".git", "node_modules", "target", "build",
21+
".gradle", "__pycache__", ".mvn", ".idea",
22+
])
23+
24+
25+
def main():
26+
root = sys.argv[1] if len(sys.argv) > 1 else "."
27+
changed = 0
28+
for dirpath, dirnames, filenames in os.walk(root, topdown=True):
29+
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
30+
for fname in filenames:
31+
if fname != "checkstyle-header.txt":
32+
continue
33+
path = os.path.join(dirpath, fname)
34+
try:
35+
with open(path, "r", encoding="utf-8") as f:
36+
current = f.read()
37+
if current == CHECKSTYLE_HEADER:
38+
print(f" Already up to date: {path}")
39+
continue
40+
with open(path, "w", encoding="utf-8") as f:
41+
f.write(CHECKSTYLE_HEADER)
42+
print(f" Updated: {path}")
43+
changed += 1
44+
except Exception as e:
45+
print(f" WARNING: cannot process {path}: {e}")
46+
print(f"\nUpdated checkstyle headers in {changed} file(s).")
47+
return 0
48+
49+
50+
if __name__ == "__main__":
51+
sys.exit(main())

0 commit comments

Comments
 (0)