Skip to content

Commit b9309d6

Browse files
committed
Fix test discovery to never return root module in fast builds
The test_discovery.py script was incorrectly returning "." (root module) when root pom.xml was changed, causing fast builds to run ALL tests instead of being targeted. This defeats the purpose of fast builds. Key fixes: - Exclude root pom.xml from relevant file detection - Never return root module from _find_module_for_file - Add debugging to show when root module is excluded This ensures fast builds NEVER run full test suites, even when version bumps or other root changes occur. The full CI/CD build will handle comprehensive testing. Signed-off-by: mark.pollack@broadcom.com
1 parent 0b8ddfc commit b9309d6

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

.github/scripts/test_discovery.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def _get_changed_files(self, base_ref: Optional[str] = None) -> List[str]:
6262
pr_head = os.environ.get('GITHUB_HEAD_HEAD') # PRs
6363
branch = os.environ.get('GITHUB_REF_NAME') # pushes
6464

65-
# For maintenance branches (cherry-picks), use single commit diff
66-
if branch and branch.endswith('.x'):
67-
# Maintenance branch - use diff with previous commit
65+
# For maintenance branches (cherry-picks) or main branch pushes, use single commit diff
66+
if (branch and branch.endswith('.x')) or (branch == 'main'):
67+
# Maintenance branch or main branch - use diff with previous commit
6868
cmd = ["git", "diff", "--name-only", "HEAD~1", "HEAD"]
6969
elif base_ref:
7070
# Explicit base reference provided - use two-dot diff for direct comparison
@@ -112,9 +112,15 @@ def _discover_affected_modules(self, changed_files: List[str]) -> List[str]:
112112

113113
for file_path in changed_files:
114114
module = self._find_module_for_file(file_path)
115-
if module:
115+
# DEBUG: Print what we're finding
116+
print(f"DEBUG: file={file_path} -> module={module}", file=sys.stderr)
117+
if module and module != ".": # Exclude root module to prevent full builds
116118
modules.add(module)
119+
print(f"DEBUG: Added module: {module}", file=sys.stderr)
120+
elif module == ".":
121+
print(f"DEBUG: Excluded root module for file: {file_path}", file=sys.stderr)
117122

123+
print(f"DEBUG: Final modules before return: {sorted(list(modules))}", file=sys.stderr)
118124
return sorted(list(modules))
119125

120126
def _find_module_for_file(self, file_path: str) -> Optional[str]:
@@ -128,25 +134,32 @@ def _find_module_for_file(self, file_path: str) -> Optional[str]:
128134

129135
for i in range(len(path_parts), 0, -1):
130136
potential_module = '/'.join(path_parts[:i])
137+
# Handle root case - empty string becomes "."
138+
if not potential_module:
139+
potential_module = "."
131140
pom_path = self.repo_root / potential_module / "pom.xml"
132141

133142
if pom_path.exists():
143+
# Never return root module to prevent full builds
144+
if potential_module == ".":
145+
return None
134146
# Found a module - return the relative path from repo root
135147
return potential_module
136148

137-
# Check if it's in the root module
138-
if (self.repo_root / "pom.xml").exists():
139-
return "."
140-
149+
# Never return root module to prevent full builds
141150
return None
142151

143152
def _is_relevant_file(self, file_path: str) -> bool:
144153
"""Check if a file is relevant for module discovery"""
154+
# Always exclude root pom.xml to prevent full builds
155+
if file_path == 'pom.xml':
156+
return False
157+
145158
# Include Java source and test files
146159
if file_path.endswith('.java'):
147160
return True
148161

149-
# Include build files
162+
# Include build files (but not root pom.xml - handled above)
150163
if file_path.endswith('pom.xml'):
151164
return True
152165

@@ -179,8 +192,9 @@ def _detect_default_base(self) -> str:
179192
branch = os.environ.get('GITHUB_REF_NAME')
180193

181194
# Show the actual strategy being used
182-
if branch and branch.endswith('.x'):
183-
return f"git diff HEAD~1 HEAD (maintenance branch {branch})"
195+
if (branch and branch.endswith('.x')) or (branch == 'main'):
196+
branch_type = "maintenance" if branch.endswith('.x') else "main"
197+
return f"git diff HEAD~1 HEAD ({branch_type} branch {branch})"
184198
elif pr_base:
185199
return f"origin/{pr_base} (PR base)"
186200
elif branch:

0 commit comments

Comments
 (0)