Skip to content
Merged
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
46 changes: 33 additions & 13 deletions .github/scripts/commit_prefix_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ def infer_prefix_from_paths(paths):
if p.startswith("lib/"):
component_prefixes.add("lib:")

# ----- tests/ → tests: -----
# ----- tests/<category>/<file>.c<file>: (strip flb_) -----
if p.startswith("tests/"):
component_prefixes.add("tests:")
parts = p.split("/")
if len(parts) >= 3:
filename = os.path.basename(p)
name, _ = os.path.splitext(filename)
if name.startswith("flb_"):
name = name[4:]
if name:
component_prefixes.add(f"{name}:")
component_prefixes.add("tests:")
Comment thread
cosmo0920 marked this conversation as resolved.
else:
component_prefixes.add("tests:")

# ----- plugins/<name>/ → <name>: -----
if p.startswith("plugins/"):
Expand Down Expand Up @@ -229,25 +239,35 @@ def validate_commit(commit):
}

# Prefixes that are allowed to cover multiple subcomponents
umbrella_prefixes = {"lib:"}
umbrella_prefixes = {"lib:", "tests:"}

# If more than one non-build prefix is inferred AND the subject is not an umbrella
# prefix, check if the subject prefix is in the expected list. If it is, allow it
# (because the corresponding file exists). Only reject if it's not in the expected list
# or if it's an umbrella prefix that doesn't match.
if len(non_build_prefixes) > 1:
# Only umbrella prefixes are allowed to cover multiple components
if subj_lower in umbrella_prefixes:
# Ensure all changed paths are within the umbrella domain
norm_paths = [p.replace(os.sep, "/") for p in files]
if not all(p.startswith("lib/") for p in norm_paths):
expected_list = sorted(expected)
expected_str = ", ".join(expected_list)
return False, (
f"Subject prefix '{subject_prefix}' does not match files changed.\n"
f"Expected one of: {expected_str}"
)
elif subj_lower not in umbrella_prefixes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of this line seems to contradict the concept of umbrella prefix, e.g. I failed to find correct prefix in #7608 for f897b94 commit which includes following files:

  1. include/fluent-bit/flb_lib.h
  2. include/fluent-bit/flb_output.h
  3. src/flb_engine_dispatch.c
  4. src/flb_lib.c

I use lib: prefix ("lib: support of tests which require callback context depending on configuration" commit message), but this script complains:

❌ Commit f897b943a0 failed:
Subject prefix 'lib:' does not match files changed.
Expected one of: engine_dispatch:, lib:


if subj_lower == "lib:":
if not all(p.startswith("lib/") for p in norm_paths):
expected_list = sorted(expected)
expected_str = ", ".join(expected_list)
return False, (
f"Subject prefix '{subject_prefix}' does not match files changed.\n"
f"Expected one of: {expected_str}"
)

elif subj_lower == "tests:":
if not all(p.startswith("tests/") for p in norm_paths):
expected_list = sorted(expected)
expected_str = ", ".join(expected_list)
return False, (
f"Subject prefix '{subject_prefix}' does not match files changed.\n"
f"Expected one of: {expected_str}"
)

else:
expected_list = sorted(expected)
expected_str = ", ".join(expected_list)
return False, (
Expand Down
20 changes: 19 additions & 1 deletion .github/scripts/tests/test_commit_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,30 @@ def test_valid_test_file_changes():
Generic prefixes like "tests:" are acceptable for test-related changes.
"""
commit = make_commit(
"tests: add unit test\n\nSigned-off-by: User",
"tests: test_router: add unit test\n\nSigned-off-by: User",
["tests/unit/test_router.c"]
)
ok, _ = validate_commit(commit)
assert ok is True


def test_invalid_test_file_changes_without_umbrella_prefix():
"""
Test that test file changes are disallowed without tests umbrella under tests components.


Test files (in tests/ directory) basically allows tests umbrella prefix.
Without "tests:" umbrella prefix are not acceptable for test-related changes.
"""
commit = make_commit(
"test_router: add unit test\n\nSigned-off-by: User",
["tests/internal/test_router.c"]
)
ok, msg = validate_commit(commit)
assert ok is False
assert "Expected one of: test_router:, tests:" in msg


def test_valid_build_file_changes():
"""
Test that build system file changes are allowed with generic prefixes.
Expand Down
Loading