Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pre-commit-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ inputs:
Name of the reuse Jinja2 template in .reuse/templates/ (without .jinja2 suffix). Consumer repos can provide their own template. Defaults to "opensovd".
required: false
default: 'opensovd'
ignore-paths:
description: >
Comma-separated list of file patterns to ignore during REUSE checks (e.g., "*.md,docs/**,*.txt"). Files matching these patterns will be skipped by reuse annotate.
required: false
default: ''

runs:
using: 'composite'
Expand Down Expand Up @@ -99,4 +104,5 @@ runs:
--hook-script="${GITHUB_ACTION_PATH}/reuse-annotate-hook.py" \
--copyright="${{ inputs.copyright-text }}" \
--license="${{ inputs.license }}" \
--template="${{ inputs.reuse-template }}"
--template="${{ inputs.reuse-template }}" \
--ignore-paths="${{ inputs.ignore-paths }}"
34 changes: 34 additions & 0 deletions pre-commit-action/reuse-annotate-hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
DEFAULT_COPYRIGHT = "The Contributors to Eclipse OpenSOVD (see CONTRIBUTORS)"
DEFAULT_LICENSE = "Apache-2.0"
DEFAULT_TEMPLATE = "opensovd"
DEFAULT_IGNORE_PATHS = ""
STYLES_CONFIG = ".reuse/styles.toml"


Expand Down Expand Up @@ -163,10 +164,39 @@ def fix_wrong_copyright(filepath: str, copyright_text: str) -> None:
path.write_text("".join(lines))


def should_ignore(filepath: str, ignore_patterns: list[str]) -> bool:
"""Check if a file should be ignored based on ignore patterns."""
if not ignore_patterns:
return False

# Normalize the filepath
filepath = filepath.replace("\\", "/")

for pattern in ignore_patterns:
pattern = pattern.strip()
if not pattern:
continue

# Support both simple glob patterns and path-based patterns
if fnmatch(filepath, pattern):
return True

# Also check just the filename
basename = os.path.basename(filepath)
if fnmatch(basename, pattern):
return True

return False


def main() -> int:
copyright_text = os.environ.get("REUSE_COPYRIGHT", DEFAULT_COPYRIGHT)
license_id = os.environ.get("REUSE_LICENSE", DEFAULT_LICENSE)
template = os.environ.get("REUSE_TEMPLATE", DEFAULT_TEMPLATE)
ignore_paths_str = os.environ.get("REUSE_IGNORE_PATHS", DEFAULT_IGNORE_PATHS)

# Parse ignore patterns from comma-separated string
ignore_patterns = [p.strip() for p in ignore_paths_str.split(",") if p.strip()]

files = sys.argv[1:]
if not files:
Expand All @@ -181,6 +211,10 @@ def main() -> int:
styles = load_styles()

for filepath in files:
# Skip ignored files
if should_ignore(filepath, ignore_patterns):
continue

# Never annotate license text files in the LICENSES/ directory
if filepath.startswith("LICENSES/") or "/LICENSES/" in filepath:
continue
Expand Down
12 changes: 11 additions & 1 deletion run_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def patch_config(config_content, *, fix_mode):


def patch_hook_script(
script_content, *, copyright_text, license_id, template, fix_mode
script_content, *, copyright_text, license_id, template, ignore_paths, fix_mode
):
"""Patch the reuse-annotate hook script with configured values.

Expand All @@ -89,6 +89,10 @@ def patch_hook_script(
'DEFAULT_TEMPLATE = "opensovd"',
f'DEFAULT_TEMPLATE = "{template}"',
)
script_content = script_content.replace(
'DEFAULT_IGNORE_PATHS = ""',
f'DEFAULT_IGNORE_PATHS = "{ignore_paths}"',
)

return script_content

Expand Down Expand Up @@ -181,6 +185,11 @@ def main():
action="store_true",
help="Run in check-only mode (no auto-fix). Used in CI to report issues without modifying files.",
)
parser.add_argument(
"--ignore-paths",
default="",
help="Comma-separated list of file patterns to ignore during REUSE checks (e.g., '*.md,docs/**,*.txt')",
)

args = parser.parse_args()

Expand Down Expand Up @@ -249,6 +258,7 @@ def main():
copyright_text=args.copyright,
license_id=args.license,
template=args.template,
ignore_paths=args.ignore_paths,
fix_mode=fix_mode,
)

Expand Down
Loading