Skip to content

Commit 51086f8

Browse files
committed
feat: add comprehensive debugging to maintenance workflow
- Add detailed git state verification to 'Compute impacted modules' step - Test different git diff approaches before running the script - Add bash debug mode (set -x) for full command tracing - Enhanced error handling in test_discovery.py with full traceback - Track and display which git command was actually executed - Add exit code and output parsing for better debugging This will help diagnose exactly what's happening in GitHub Actions instead of the current whack-a-mole debugging approach.
1 parent 1319671 commit 51086f8

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

.github/scripts/test_discovery.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CITestDiscovery:
2020

2121
def __init__(self, repo_root: Path = Path(".")):
2222
self.repo_root = Path(repo_root)
23+
self._last_git_command = None
2324

2425
def modules_from_diff(self, base_ref: Optional[str] = None, verbose: bool = False) -> str:
2526
"""Get affected modules from git diff (for GitHub Actions)"""
@@ -31,6 +32,7 @@ def modules_from_diff(self, base_ref: Optional[str] = None, verbose: bool = Fals
3132
if verbose:
3233
detected_base = base_ref if base_ref else self._detect_default_base()
3334
print(f"Detected base ref: {detected_base}", file=sys.stderr)
35+
print(f"Git diff strategy used: {self._get_last_git_command()}", file=sys.stderr)
3436
print(f"Changed files ({len(changed_files)}):", file=sys.stderr)
3537
for file in changed_files[:10]: # Limit to first 10 for readability
3638
print(f" - {file}", file=sys.stderr)
@@ -78,6 +80,7 @@ def _get_changed_files(self, base_ref: Optional[str] = None) -> List[str]:
7880
cmd = ["git", "diff", "--name-only", "HEAD~1..HEAD"]
7981

8082
# Execute the git diff command
83+
self._last_git_command = ' '.join(cmd) # Store for debugging
8184
result = subprocess.run(
8285
cmd,
8386
cwd=self.repo_root,
@@ -92,9 +95,15 @@ def _get_changed_files(self, base_ref: Optional[str] = None) -> List[str]:
9295
except subprocess.CalledProcessError as e:
9396
print(f"Git command failed: {e}", file=sys.stderr)
9497
print(f"Command: {' '.join(e.cmd) if hasattr(e, 'cmd') else 'unknown'}", file=sys.stderr)
98+
print(f"Exit code: {e.returncode}", file=sys.stderr)
99+
print(f"Stdout: {e.stdout if hasattr(e, 'stdout') else 'N/A'}", file=sys.stderr)
100+
print(f"Stderr: {e.stderr if hasattr(e, 'stderr') else 'N/A'}", file=sys.stderr)
95101
return []
96102
except Exception as e:
97103
print(f"Error getting changed files: {e}", file=sys.stderr)
104+
print(f"Error type: {type(e).__name__}", file=sys.stderr)
105+
import traceback
106+
print(f"Traceback: {traceback.format_exc()}", file=sys.stderr)
98107
return []
99108

100109
def _discover_affected_modules(self, changed_files: List[str]) -> List[str]:
@@ -178,6 +187,10 @@ def _detect_default_base(self) -> str:
178187
return f"HEAD~1 (single commit - branch {branch})"
179188
else:
180189
return "HEAD~1 (single commit - fallback)"
190+
191+
def _get_last_git_command(self) -> str:
192+
"""Get the last git command executed for debugging"""
193+
return self._last_git_command or "No git command executed yet"
181194

182195

183196
def modules_from_diff_cli():

.github/workflows/maintenance-fast.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,47 @@ jobs:
3838
- name: Compute impacted modules
3939
id: mods
4040
run: |
41-
MODS=$(python3 .github/scripts/test_discovery.py modules-from-diff --base "origin/$GITHUB_REF_NAME" --verbose)
42-
echo "modules=$MODS" >> "$GITHUB_OUTPUT"
41+
echo "=== Module Detection Debug Info ==="
42+
echo "Environment variables:"
43+
echo " GITHUB_REF_NAME: $GITHUB_REF_NAME"
44+
echo " GITHUB_REF: $GITHUB_REF"
45+
echo " PWD: $(pwd)"
46+
echo ""
47+
48+
echo "Git state verification:"
49+
echo " HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'FAILED')"
50+
echo " HEAD~1: $(git rev-parse HEAD~1 2>/dev/null || echo 'NOT AVAILABLE')"
51+
echo " Branch: $(git branch --show-current 2>/dev/null || echo 'DETACHED')"
52+
echo ""
53+
54+
echo "Testing different git diff approaches:"
55+
echo "1. HEAD~1..HEAD:"
56+
git diff --name-only HEAD~1..HEAD 2>&1 | head -10 || echo " FAILED: $?"
57+
58+
echo "2. git show HEAD:"
59+
git show --name-only --format= HEAD 2>&1 | head -10 || echo " FAILED: $?"
60+
61+
echo "3. Recent commits:"
62+
git log --oneline -3 2>/dev/null || echo " Git log failed"
63+
echo ""
64+
65+
echo "=== Running test_discovery.py with full debugging ==="
66+
set -x # Enable bash debug mode
67+
MODS=$(python3 .github/scripts/test_discovery.py modules-from-diff --base "origin/$GITHUB_REF_NAME" --verbose 2>&1)
68+
EXIT_CODE=$?
69+
set +x # Disable bash debug mode
70+
71+
echo ""
72+
echo "=== Test Discovery Results ==="
73+
echo "Exit code: $EXIT_CODE"
74+
echo "Output:"
75+
echo "$MODS"
76+
echo ""
77+
78+
# Extract just the module list (last line that isn't stderr logging)
79+
MODULE_LIST=$(echo "$MODS" | grep -v "^Detected base ref:" | grep -v "^Changed files" | grep -v "^Final module list:" | tail -1)
80+
echo "Extracted modules: '$MODULE_LIST'"
81+
echo "modules=$MODULE_LIST" >> "$GITHUB_OUTPUT"
4382
4483
- name: Test affected modules with integration tests
4584
env:

0 commit comments

Comments
 (0)