1+ #!/usr/bin/env python3
2+ """
3+ Diagnose and potentially fix workflow status issues
4+ """
5+
6+ import subprocess
7+ import json
8+ import sys
9+
10+
11+ def run_command (cmd ):
12+ """Run shell command and return output."""
13+ try :
14+ result = subprocess .run (cmd , shell = True , capture_output = True , text = True )
15+ return result .stdout .strip (), result .stderr .strip (), result .returncode
16+ except Exception as e :
17+ return "" , str (e ), 1
18+
19+
20+ def get_workflow_status ():
21+ """Get detailed workflow status."""
22+ print ("🔍 Analyzing current workflow status...\n " )
23+
24+ # Get latest CI run
25+ cmd = "gh run list --repo cloudQuant/pyfolio --workflow ci.yml --limit 1 --json databaseId,status,conclusion,jobs"
26+ stdout , stderr , code = run_command (cmd )
27+
28+ if code != 0 :
29+ print (f"❌ Failed to get workflow info: { stderr } " )
30+ return False
31+
32+ try :
33+ runs = json .loads (stdout )
34+ if not runs :
35+ print ("❌ No workflow runs found" )
36+ return False
37+
38+ run = runs [0 ]
39+ run_id = run .get ('databaseId' )
40+
41+ print (f"📊 Latest Run ID: { run_id } " )
42+ print (f"📊 Status: { run .get ('status' )} " )
43+ print (f"📊 Conclusion: { run .get ('conclusion' )} " )
44+ print ()
45+
46+ # Get detailed job information
47+ cmd = f"gh run view { run_id } --repo cloudQuant/pyfolio --json jobs"
48+ stdout , stderr , code = run_command (cmd )
49+
50+ if code != 0 :
51+ print (f"❌ Failed to get job details: { stderr } " )
52+ return False
53+
54+ run_details = json .loads (stdout )
55+ jobs = run_details .get ('jobs' , [])
56+
57+ print ("📋 Job Status Summary:" )
58+ all_core_passed = True
59+
60+ for job in jobs :
61+ name = job .get ('name' , 'Unknown' )
62+ conclusion = job .get ('conclusion' , 'unknown' )
63+
64+ # Identify core jobs
65+ is_core = any (keyword in name .lower () for keyword in
66+ ['test python' , 'lint' , 'build distribution' ])
67+
68+ if is_core :
69+ status_icon = "✅" if conclusion == "success" else "❌"
70+ print (f" { status_icon } { name } : { conclusion } (CORE)" )
71+ if conclusion != "success" :
72+ all_core_passed = False
73+ else :
74+ status_icon = "✅" if conclusion == "success" else "⚠️"
75+ optional_tag = " (OPTIONAL)" if "install" in name .lower () else ""
76+ print (f" { status_icon } { name } : { conclusion } { optional_tag } " )
77+
78+ print ()
79+
80+ # Analysis
81+ if all_core_passed and run .get ('conclusion' ) == 'failure' :
82+ print ("⚠️ ISSUE DETECTED:" )
83+ print (" All core jobs passed but workflow shows as failed" )
84+ print (" This suggests a workflow configuration issue" )
85+ return False
86+ elif all_core_passed :
87+ print ("✅ ANALYSIS:" )
88+ print (" All core jobs passed - workflow should show success" )
89+ return True
90+ else :
91+ print ("❌ ANALYSIS:" )
92+ print (" Core jobs failed - workflow correctly shows failure" )
93+ return False
94+
95+ except json .JSONDecodeError as e :
96+ print (f"❌ Failed to parse workflow data: { e } " )
97+ return False
98+
99+
100+ def suggest_fixes ():
101+ """Suggest potential fixes."""
102+ print ("\n 💡 Suggested Actions:" )
103+ print ()
104+ print ("1. **Immediate fixes:**" )
105+ print (" - Check if any hidden jobs are failing" )
106+ print (" - Verify no syntax errors in workflow YAML" )
107+ print (" - Ensure no required status checks are blocking" )
108+ print ()
109+ print ("2. **Diagnostic commands:**" )
110+ print (" - gh run list --repo cloudQuant/pyfolio --workflow ci.yml --limit 5" )
111+ print (" - gh run view [RUN_ID] --repo cloudQuant/pyfolio --log" )
112+ print ()
113+ print ("3. **Potential solutions:**" )
114+ print (" - Remove problematic continue-on-error jobs" )
115+ print (" - Simplify workflow to only essential jobs" )
116+ print (" - Check for GitHub Actions service issues" )
117+ print ()
118+ print ("4. **Reset options:**" )
119+ print (" - Create a simple test workflow to isolate issues" )
120+ print (" - Temporarily disable non-essential jobs" )
121+
122+
123+ def main ():
124+ """Main function."""
125+ print ("🔧 Workflow Status Diagnostic Tool\n " )
126+
127+ # Check if gh is available
128+ stdout , stderr , code = run_command ("gh --version" )
129+ if code != 0 :
130+ print ("❌ GitHub CLI not found. Please install from: https://cli.github.com/" )
131+ sys .exit (1 )
132+
133+ # Analyze current status
134+ status_ok = get_workflow_status ()
135+
136+ if not status_ok :
137+ suggest_fixes ()
138+ else :
139+ print ("✅ Workflow status appears correct" )
140+ print ("\n If badge still shows failure:" )
141+ print (" python scripts/check_badge_status.py refresh" )
142+
143+
144+ if __name__ == "__main__" :
145+ main ()
0 commit comments