3232
3333
3434def validate_paths ():
35- """Validate that required files and directories exist."""
36- required_files = [
35+ """
36+ Validate that required files exist.
37+
38+ Note: Only validates files needed for recategorization if SARIF exists.
39+ Returns:
40+ True if validation passes or SARIF doesn't exist, False on critical errors
41+ """
42+ # First check if SARIF file exists - if not, nothing to recategorize
43+ if not Path (SARIF_FILE ).exists ():
44+ print (f"Info: SARIF file not found at { SARIF_FILE } " , file = sys .stderr )
45+ return False # Signal to skip recategorization
46+
47+ # SARIF exists, check for recategorization dependencies
48+ optional_files = [
3749 RECATEGORIZE_SCRIPT ,
38- CODING_STANDARDS_CONFIG ,
3950 CODING_STANDARDS_SCHEMA ,
4051 SARIF_SCHEMA ,
41- SARIF_FILE ,
4252 ]
4353
54+ required_files = [
55+ CODING_STANDARDS_CONFIG ,
56+ ]
57+
58+ # Check required files (fail if missing)
4459 for file_path in required_files :
4560 if not Path (file_path ).exists ():
4661 print (f"Error: Required file not found: { file_path } " , file = sys .stderr )
4762 return False
4863
64+ # Warn about optional files but don't fail
65+ missing_optional = []
66+ for file_path in optional_files :
67+ if not Path (file_path ).exists ():
68+ missing_optional .append (file_path )
69+
70+ if missing_optional :
71+ print (f"Warning: Some recategorization files not found: { missing_optional } " , file = sys .stderr )
72+ print ("Recategorization will be skipped, but filtering will still be applied." , file = sys .stderr )
73+
4974 return True
5075
5176
@@ -54,8 +79,14 @@ def recategorize_sarif():
5479 Run the CodeQL recategorization script on SARIF results.
5580
5681 Returns:
57- True if successful, False otherwise
82+ True if successful or skipped , False on critical errors
5883 """
84+ # Check if recategorization script exists
85+ if not Path (RECATEGORIZE_SCRIPT ).exists ():
86+ print (f"Info: Recategorization script not found at { RECATEGORIZE_SCRIPT } " , file = sys .stderr )
87+ print ("Skipping recategorization step (will apply filtering only)." , file = sys .stderr )
88+ return True # Not a failure, just skip this step
89+
5990 # Create output directory
6091 output_path = Path (OUTPUT_DIR )
6192 output_path .mkdir (parents = True , exist_ok = True )
@@ -172,12 +203,17 @@ def filter_sarif_results():
172203def main ():
173204 """Main entry point."""
174205 # Validate required files exist
175- if not validate_paths ():
176- sys .exit (1 )
206+ has_sarif = validate_paths ()
177207
178- # Run recategorization
208+ if not has_sarif :
209+ # No SARIF file to process - this is normal before CodeQL analysis runs
210+ print ("No SARIF file found - skipping recategorization." )
211+ print ("This is expected if CodeQL analysis hasn't completed yet." )
212+ sys .exit (0 )
213+
214+ # Run recategorization (will skip gracefully if script not available)
179215 if not recategorize_sarif ():
180- sys .exit ( 1 )
216+ print ( "Warning: Recategorization failed, continuing with filtering..." , file = sys .stderr )
181217
182218 # Filter SARIF results to only include repos/*
183219 if not filter_sarif_results ():
0 commit comments