1+ #!/usr/bin/env python3
2+
3+ import os
4+ import subprocess
5+ import shutil
6+
7+ # Define paths
8+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
9+ project_root = os .path .dirname (script_dir )
10+ errors_dir = os .path .join (project_root , "modules" , "ROOT" , "pages" , "errors" , "gql-errors" )
11+ index_file = os .path .join (errors_dir , "index.adoc" )
12+ auto_index_file = os .path .join (errors_dir , "auto-index.adoc" )
13+
14+ def run_python_script (script_name ):
15+ """Run a Python script and return its exit code"""
16+ script_path = os .path .join (script_dir , script_name )
17+ result = subprocess .run (["python3" , script_path ], capture_output = True , text = True )
18+ print (result .stdout )
19+ return result .returncode
20+
21+ # Main workflow
22+ def main ():
23+ print ("===== Starting GQL Error Index Update Process =====" )
24+
25+ # Step 1: Validate index.adoc
26+ print ("Step 1: Validating index.adoc against individual files..." )
27+ validation_result = run_python_script ("validate-error-index.py" )
28+
29+ # Step 2: Check validation result
30+ if validation_result == 0 :
31+ print ("✅ Validation passed! No further action needed." )
32+ return 0
33+
34+ # Step 3: Generate auto-index.adoc
35+ print ("Step 3: Generating auto-index.adoc from template..." )
36+ generation_result = run_python_script ("generate-gql-error-index-from-template.py" )
37+
38+ if generation_result != 0 or not os .path .exists (auto_index_file ):
39+ print ("Error: Failed to generate auto-index.adoc" )
40+ return 1
41+
42+ # Step 4: Validate auto-index.adoc
43+ print ("Step 4: Validating auto-index.adoc against individual files..." )
44+ auto_validation_result = run_python_script ("validate-error-auto-index.py" )
45+
46+ # Step 5: If auto-index validation passes, replace index.adoc
47+ if auto_validation_result == 0 :
48+ print ("Step 5: Auto-index validation passed! Replacing index.adoc..." )
49+
50+ # Replace index with auto-index
51+ os .remove (index_file )
52+ os .rename (auto_index_file , index_file )
53+
54+ print ("✅ Update completed successfully." )
55+ return 0
56+ else :
57+ print ("❌ Auto-index validation failed." )
58+ print ("No changes were made to index.adoc." )
59+ return auto_validation_result
60+
61+ if __name__ == "__main__" :
62+ exit (main ())
0 commit comments