Skip to content

Commit d2c9a2c

Browse files
committed
changes
1 parent ecd58ae commit d2c9a2c

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

.github/workflows/validate-queries.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ jobs:
1313
with:
1414
fetch-depth: 0 # Required for git diff detection
1515

16-
- name: Debug filesystem
17-
if: ${{ always() }}
18-
run: |
19-
echo "Workspace contents:"
20-
ls -R
21-
echo "Scripts directory:"
22-
ls -la scripts/
23-
2416
- name: Set up Python
2517
uses: actions/setup-python@v4
2618
with:

scripts/validate_queries.py

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,73 @@
11
#!/usr/bin/env python3
22
import re
33
import sys
4+
import os
45
from pathlib import Path
56
from sumologic_client import SumoLogicClient
67

78
def find_sql_blocks_in_pr():
8-
"""Detect changed SQL blocks without file modifications"""
9-
changed_files = sys.argv[1:] if len(sys.argv) > 1 else [
10-
str(p) for p in Path("docs").rglob("*.md")
11-
if "search-query-language" in str(p)
12-
]
13-
14-
sql_blocks = []
15-
for file in changed_files:
16-
content = Path(file).read_text()
17-
sql_blocks.extend([
18-
(file, sql.strip())
19-
for sql in re.findall(r'```sql\n(.*?)```', content, re.DOTALL)
20-
])
21-
return sql_blocks
9+
"""Detect changed SQL blocks with better debugging"""
10+
print("::group::Detecting SQL blocks") # GitHub Actions log grouping
11+
12+
# Get changed files from environment if running in GitHub Actions
13+
changed_files = sys.argv[1:] if len(sys.argv) > 1 else []
14+
if not changed_files and "GITHUB_ACTIONS" in os.environ:
15+
try:
16+
with open(os.environ["GITHUB_EVENT_PATH"]) as f:
17+
event_data = json.load(f)
18+
changed_files = [
19+
f"docs/{f['filename']}" for f in
20+
event_data.get("pull_request", {}).get("files", [])
21+
if f['filename'].endswith('.md')
22+
]
23+
except Exception as e:
24+
print(f"::warning::Couldn't get changed files: {str(e)}")
25+
26+
if not changed_files:
27+
changed_files = [
28+
str(p) for p in Path("docs").rglob("*.md")
29+
if "search-query-language" in str(p)
30+
]
31+
32+
print(f"Files to scan: {changed_files}")
33+
return changed_files
2234

2335
def validate_queries():
36+
print("::group::Starting validation")
2437
client = SumoLogicClient()
2538
failed = False
2639

27-
for file, query in find_sql_blocks_in_pr():
28-
print(f"Validating SQL in {file}...")
40+
for file, query in find_sql_blocks_with_content():
41+
print(f"\n🔍 Validating query in {file}")
42+
print(f"Query sample:\n{query[:200]}...") # Show first 200 chars
43+
2944
try:
45+
print("Calling Sumo Logic API...")
3046
if not client.test_query(query):
3147
print(f"::error file={file},title=Query Validation Failed::Query returned no results")
3248
failed = True
49+
else:
50+
print("✅ Query validated successfully")
3351
except Exception as e:
3452
print(f"::error file={file},title=Query Execution Failed::{str(e)}")
3553
failed = True
3654

55+
print("::endgroup::")
3756
if failed:
3857
sys.exit(1)
3958

59+
def find_sql_blocks_with_content():
60+
"""Yields (file_path, query) tuples with better error handling"""
61+
for file in find_sql_blocks_in_pr():
62+
try:
63+
content = Path(file).read_text()
64+
queries = re.findall(r'```sql\n(.*?)```', content, re.DOTALL)
65+
for query in queries:
66+
query = query.strip()
67+
if query: # Skip empty queries
68+
yield (file, query)
69+
except Exception as e:
70+
print(f"::warning file={file}::Error processing file: {str(e)}")
71+
4072
if __name__ == "__main__":
41-
validate_queries()
73+
validate_queries()

0 commit comments

Comments
 (0)