77 branches : [ main, develop ]
88
99jobs :
10+ # Job 1: Standard Harmony Check (fails on high/critical)
1011 harmony-check :
1112 runs-on : ubuntu-latest
1213
@@ -17,44 +18,178 @@ jobs:
1718 - name : Set up Python
1819 uses : actions/setup-python@v4
1920 with :
20- python-version : ' 3.8 '
21+ python-version : ' 3.11 '
2122
2223 - name : Install Python Code Harmonizer
2324 run : |
2425 python -m pip install --upgrade pip
2526 pip install .
2627
27- - name : Run Harmony Analysis
28+ - name : Run Harmony Analysis on Source Code
2829 run : |
29- echo "========================================"
30- echo "Python Code Harmonizer - CI/CD Check"
31- echo "========================================"
30+ echo "🔍 Checking Code Harmony..."
31+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
3232
33- # Analyze all Python files in src/ directory
34- harmonizer src/**/*.py || true
33+ # v1.2+ automatically fails on high/critical disharmony
34+ # Exit codes: 0=harmonious, 1=medium, 2=high, 3=critical
35+ harmonizer src/**/*.py
3536
36- # Note: Currently harmonizer doesn't set exit codes based on scores
37- # Future enhancement: fail build if critical disharmony detected
37+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
38+ echo "✅ Harmony check passed - no critical issues found!"
3839
40+ - name : Run Harmony Analysis on Tests (informational)
41+ run : |
42+ echo ""
43+ echo "📊 Checking Test Code Harmony (informational only)..."
44+
45+ # For tests, we allow higher disharmony (don't fail the build)
46+ harmonizer tests/**/*.py || echo "⚠️ Test code has some disharmony (acceptable)"
47+ continue-on-error : true
48+
49+ # Job 2: Detailed JSON Report with Artifact
50+ harmony-json-report :
51+ runs-on : ubuntu-latest
52+
53+ steps :
54+ - name : Checkout code
55+ uses : actions/checkout@v3
56+
57+ - name : Set up Python
58+ uses : actions/setup-python@v4
59+ with :
60+ python-version : ' 3.11'
61+
62+ - name : Install Python Code Harmonizer
63+ run : |
64+ python -m pip install --upgrade pip
65+ pip install .
66+
67+ - name : Generate JSON Harmony Report
68+ run : |
69+ echo "📋 Generating detailed JSON harmony report..."
70+
71+ # Generate JSON report for all Python files
72+ harmonizer --format json src/**/*.py examples/**/*.py tests/**/*.py > harmony-report.json || true
73+
74+ # Pretty-print the summary
3975 echo ""
40- echo "✅ Harmony check completed"
41- echo "Review output above for any disharmony warnings"
76+ echo "📊 Harmony Summary:"
77+ cat harmony-report.json | python -c "
78+ import json, sys
79+ data = json.load(sys.stdin)
80+ summary = data['summary']
81+ print(f\" Total files: {summary['total_files']}\")
82+ print(f\" Total functions: {summary['total_functions']}\")
83+ print(f\" Severity breakdown:\")
84+ for sev, count in summary['severity_counts'].items():
85+ if count > 0:
86+ emoji = {'critical': '🔴', 'high': '🟠', 'medium': '🟡', 'low': '🔵', 'excellent': '🟢'}.get(sev, '⚪')
87+ print(f\" {emoji} {sev.capitalize()}: {count}\")
88+ print(f\" Highest severity: {summary['highest_severity']}\")
89+ "
90+
91+ - name : Upload JSON Report as Artifact
92+ uses : actions/upload-artifact@v3
93+ with :
94+ name : harmony-report
95+ path : harmony-report.json
96+ retention-days : 30
4297
43- - name : Analyze specific modules (optional)
98+ - name : Display Top 5 Disharmonious Functions
4499 run : |
45- # Example: Analyze specific critical modules with comments
46100 echo ""
47- echo "Analyzing critical modules..."
101+ echo "🎯 Top 5 Functions to Refactor:"
102+ cat harmony-report.json | python -c "
103+ import json, sys
104+ data = json.load(sys.stdin)
105+ funcs = []
106+ for file in data['files']:
107+ for func in file['functions']:
108+ if func['disharmonious']:
109+ funcs.append((func['score'], func['name'], file['file'], func['severity']))
110+ funcs.sort(reverse=True)
111+ for i, (score, name, file, sev) in enumerate(funcs[:5], 1):
112+ emoji = {'critical': '🔴', 'high': '🟠', 'medium': '🟡'}.get(sev, '⚪')
113+ print(f\" {i}. {emoji} {name} ({score:.2f}) in {file}\")
114+ if not funcs:
115+ print(' 🎉 No disharmonious functions found!')
116+ "
117+
118+ # Job 3: Custom Threshold Example
119+ harmony-strict-check :
120+ runs-on : ubuntu-latest
121+
122+ steps :
123+ - name : Checkout code
124+ uses : actions/checkout@v3
48125
49- # Add your critical files here
50- # harmonizer src/core/important.py
51- # harmonizer src/api/endpoints.py
126+ - name : Set up Python
127+ uses : actions/setup-python@v4
128+ with :
129+ python-version : ' 3.11'
130+
131+ - name : Install Python Code Harmonizer
132+ run : |
133+ python -m pip install --upgrade pip
134+ pip install .
135+
136+ - name : Strict Harmony Check (threshold 0.3)
137+ run : |
138+ echo "🔒 Running STRICT harmony check (threshold: 0.3)..."
139+ echo "This enforces excellent code harmony standards."
140+ echo ""
141+
142+ # Use stricter threshold (0.3 instead of default 0.5)
143+ # This catches even minor semantic drift
144+ harmonizer --threshold 0.3 src/**/*.py || {
145+ echo ""
146+ echo "⚠️ STRICT CHECK: Code doesn't meet excellent harmony standards"
147+ echo "This is OK - default threshold (0.5) is more permissive"
148+ exit 0
149+ }
52150 continue-on-error : true
53151
54- # Note: To make this workflow fail on high disharmony scores,
55- # you'll need to wrap harmonizer in a script that checks scores
56- # and exits with non-zero code if threshold exceeded.
57- #
58- # Example future enhancement:
59- # - name: Check harmony with threshold
60- # run: python scripts/ci_harmony_check.py --threshold 0.8 --fail-on-high
152+ # Job 4: Demonstrate all exit codes
153+ harmony-exit-codes-demo :
154+ runs-on : ubuntu-latest
155+
156+ steps :
157+ - name : Checkout code
158+ uses : actions/checkout@v3
159+
160+ - name : Set up Python
161+ uses : actions/setup-python@v4
162+ with :
163+ python-version : ' 3.11'
164+
165+ - name : Install Python Code Harmonizer
166+ run : |
167+ python -m pip install --upgrade pip
168+ pip install .
169+
170+ - name : Test Exit Code Handling
171+ run : |
172+ echo "🧪 Testing Exit Code Behavior..."
173+ echo ""
174+
175+ # Test with examples/test_code.py (has critical disharmony)
176+ echo "Testing with examples/test_code.py (expect exit code 3):"
177+ if harmonizer examples/test_code.py; then
178+ echo "❌ Unexpected: Got exit code 0 (should be 3 for critical)"
179+ exit 1
180+ else
181+ EXIT_CODE=$?
182+ echo "✅ Got exit code: $EXIT_CODE"
183+ if [ $EXIT_CODE -eq 3 ]; then
184+ echo "✅ Correct: Exit code 3 indicates critical disharmony"
185+ else
186+ echo "⚠️ Unexpected exit code (expected 3)"
187+ fi
188+ fi
189+
190+ echo ""
191+ echo "Exit Code Reference:"
192+ echo " 0 = Harmonious (excellent/low)"
193+ echo " 1 = Medium severity (0.5-0.8)"
194+ echo " 2 = High severity (0.8-1.2)"
195+ echo " 3 = Critical severity (≥1.2)"
0 commit comments