Skip to content

Commit 3ce6d38

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 c5d2ccd commit 3ce6d38

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)
@@ -88,6 +90,7 @@ def _get_changed_files(self, base_ref: Optional[str] = None) -> List[str]:
8890
cmd = ["git", "diff", "--name-only", "HEAD~1..HEAD"]
8991

9092
# Execute the git diff command
93+
self._last_git_command = ' '.join(cmd) # Store for debugging
9194
result = subprocess.run(
9295
cmd,
9396
cwd=self.repo_root,
@@ -102,9 +105,15 @@ def _get_changed_files(self, base_ref: Optional[str] = None) -> List[str]:
102105
except subprocess.CalledProcessError as e:
103106
print(f"Git command failed: {e}", file=sys.stderr)
104107
print(f"Command: {' '.join(e.cmd) if hasattr(e, 'cmd') else 'unknown'}", file=sys.stderr)
108+
print(f"Exit code: {e.returncode}", file=sys.stderr)
109+
print(f"Stdout: {e.stdout if hasattr(e, 'stdout') else 'N/A'}", file=sys.stderr)
110+
print(f"Stderr: {e.stderr if hasattr(e, 'stderr') else 'N/A'}", file=sys.stderr)
105111
return []
106112
except Exception as e:
107113
print(f"Error getting changed files: {e}", file=sys.stderr)
114+
print(f"Error type: {type(e).__name__}", file=sys.stderr)
115+
import traceback
116+
print(f"Traceback: {traceback.format_exc()}", file=sys.stderr)
108117
return []
109118

110119
def _discover_affected_modules(self, changed_files: List[str]) -> List[str]:
@@ -188,6 +197,10 @@ def _detect_default_base(self) -> str:
188197
return f"HEAD~1 (single commit - branch {branch})"
189198
else:
190199
return "HEAD~1 (single commit - fallback)"
200+
201+
def _get_last_git_command(self) -> str:
202+
"""Get the last git command executed for debugging"""
203+
return self._last_git_command or "No git command executed yet"
191204

192205

193206
def modules_from_diff_cli():

.github/workflows/maintenance-fast.yml

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

0 commit comments

Comments
 (0)