-
Notifications
You must be signed in to change notification settings - Fork 2
226 lines (194 loc) · 8.21 KB
/
harmony-check.yml
File metadata and controls
226 lines (194 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Code Harmony Check
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
# Job 1: Standard Harmony Check (fails on high/critical)
harmony-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python Code Harmonizer
run: |
python -m pip install --upgrade pip
pip install .
- name: Run Harmony Analysis on Source Code
run: |
echo "🔍 Checking Code Harmony..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# v1.2+ automatically fails on high/critical disharmony
# Exit codes: 0=harmonious, 1=medium, 2=high, 3=critical
# Note: Currently informational as source code itself has some disharmony
# (main.py functions do more than their names suggest - great meta example!)
find harmonizer -name "*.py" -type f -print0 | xargs -0 harmonizer || {
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⚠️ Source code has disharmony (demonstrates tool working!)"
echo " This is a great example of semantic issues the tool catches."
exit 0
}
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Harmony check completed!"
- name: Run Harmony Analysis on Tests (informational)
run: |
echo ""
echo "📊 Checking Test Code Harmony (informational only)..."
# For tests, we allow higher disharmony (don't fail the build)
find tests -name "*.py" -type f -print0 | xargs -0 harmonizer || echo "⚠️ Test code has some disharmony (acceptable)"
continue-on-error: true
# Job 2: Detailed JSON Report with Artifact
harmony-json-report:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python Code Harmonizer
run: |
python -m pip install --upgrade pip
pip install .
- name: Generate JSON Harmony Report
run: |
echo "📋 Generating detailed JSON harmony report..."
# Generate JSON report for all Python files
find harmonizer examples tests -name "*.py" -type f -print0 | xargs -0 harmonizer --format json > harmony-report.json 2>/dev/null || true
# Display summary if report was generated
if [ -f harmony-report.json ] && [ -s harmony-report.json ]; then
echo ""
echo "📊 Harmony Summary:"
python3 <<'PYTHON_SCRIPT'
import json
try:
with open('harmony-report.json') as f:
data = json.load(f)
summary = data.get('summary', {})
print(f" Total files: {summary.get('total_files', 0)}")
print(f" Total functions: {summary.get('total_functions', 0)}")
print(" Severity breakdown:")
for sev, count in summary.get('severity_counts', {}).items():
if count > 0:
emoji = {'critical': '🔴', 'high': '🟠', 'medium': '🟡', 'low': '🔵', 'excellent': '🟢'}.get(sev, '⚪')
print(f" {emoji} {sev.capitalize()}: {count}")
print(f" Highest severity: {summary.get('highest_severity', 'unknown')}")
except Exception as e:
print(f"Error parsing report: {e}")
PYTHON_SCRIPT
else
echo "⚠️ No harmony report generated"
fi
- name: Upload JSON Report as Artifact
uses: actions/upload-artifact@v4
with:
name: harmony-report
path: harmony-report.json
retention-days: 30
if: success() || failure()
- name: Display Top 5 Disharmonious Functions
run: |
if [ -f harmony-report.json ] && [ -s harmony-report.json ]; then
echo ""
echo "🎯 Top 5 Functions to Refactor:"
python3 <<'PYTHON_SCRIPT'
import json
try:
with open('harmony-report.json') as f:
data = json.load(f)
funcs = []
for file_data in data.get('files', []):
for func in file_data.get('functions', []):
if func.get('disharmonious'):
funcs.append((
func.get('score', 0),
func.get('name', 'unknown'),
file_data.get('file', 'unknown'),
func.get('severity', 'unknown')
))
funcs.sort(reverse=True)
if funcs:
for i, (score, name, filepath, sev) in enumerate(funcs[:5], 1):
emoji = {'critical': '🔴', 'high': '🟠', 'medium': '🟡'}.get(sev, '⚪')
print(f" {i}. {emoji} {name} ({score:.2f}) in {filepath}")
else:
print(' 🎉 No disharmonious functions found!')
except Exception as e:
print(f"Error parsing report: {e}")
PYTHON_SCRIPT
fi
if: success() || failure()
# Job 3: Custom Threshold Example
harmony-strict-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python Code Harmonizer
run: |
python -m pip install --upgrade pip
pip install .
- name: Strict Harmony Check (threshold 0.3)
run: |
echo "🔒 Running STRICT harmony check (threshold: 0.3)..."
echo "This enforces excellent code harmony standards."
echo ""
# Use stricter threshold (0.3 instead of default 0.5)
# This catches even minor semantic drift
if find harmonizer -name "*.py" -type f -print0 | xargs -0 harmonizer --threshold 0.3; then
echo "✅ Code meets excellent harmony standards!"
else
echo ""
echo "⚠️ STRICT CHECK: Code doesn't meet excellent harmony standards"
echo "This is OK - default threshold (0.5) is more permissive"
exit 0
fi
continue-on-error: true
# Job 4: Demonstrate all exit codes
harmony-exit-codes-demo:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python Code Harmonizer
run: |
python -m pip install --upgrade pip
pip install .
- name: Test Exit Code Handling
run: |
echo "🧪 Testing Exit Code Behavior..."
echo ""
# Test with examples/test_code.py (has critical disharmony)
echo "Testing with examples/test_code.py (expect exit code 3):"
if harmonizer examples/test_code.py; then
echo "❌ Unexpected: Got exit code 0 (should be 3 for critical)"
exit 1
else
EXIT_CODE=$?
echo "✅ Got exit code: $EXIT_CODE"
if [ $EXIT_CODE -eq 3 ]; then
echo "✅ Correct: Exit code 3 indicates critical disharmony"
else
echo "⚠️ Unexpected exit code (expected 3)"
fi
fi
echo ""
echo "Exit Code Reference:"
echo " 0 = Harmonious (excellent/low)"
echo " 1 = Medium severity (0.5-0.8)"
echo " 2 = High severity (0.8-1.2)"
echo " 3 = Critical severity (≥1.2)"