Skip to content

Commit 0d121fb

Browse files
committed
ci: Integrate v1.2 features into CI/CD pipelines and add comprehensive guide
Fully integrated v1.2 exit codes and JSON output into CI/CD workflows, demonstrating production-ready usage. Created comprehensive integration guide for all major CI/CD platforms. Changes: 1. UPDATED .github/workflows/harmony-check.yml - Removed `|| true` - now uses exit codes to fail builds - Added 4 demonstration jobs: * harmony-check: Standard check (fails on high/critical) * harmony-json-report: Generates JSON report with artifact upload * harmony-strict-check: Custom threshold example (0.3) * harmony-exit-codes-demo: Tests exit code behavior - Shows JSON parsing to display "Top 5 Functions to Refactor" - Demonstrates different strategies (informational, strict, etc.) 2. UPDATED .github/workflows/ci.yml - Added harmony check step to main CI workflow - Runs after pytest, before workflow completes - Fails build if critical disharmony detected - Integrated into standard test suite 3. FIXED src/divine_invitation_engine_V2.py - Moved vocabulary initialization message to stderr - Prevents breaking JSON output on stdout - JSON output is now clean and parseable 4. CREATED docs/CI_CD_INTEGRATION.md (~650 lines) - Comprehensive integration guide for all platforms - Exit codes reference table with recommendations - GitHub Actions examples (3 different approaches) - GitLab CI, Jenkins, CircleCI integration examples - JSON output parsing and dashboard integration - Custom threshold strategies - Best practices for gradual rollout - Full production setup example - Troubleshooting section Key Demonstrations: Exit Codes: - 0 = Harmonious (excellent/low severity) - 1 = Medium severity (0.5-0.8) - 2 = High severity (0.8-1.2) - 3 = Critical severity (≥1.2) JSON Output: - Valid, parseable JSON on stdout - Includes severity counts and summary - Can be uploaded as CI artifacts - Enables trend tracking and dashboards Workflows Now Show: ✅ How to fail builds on disharmony ✅ How to generate and upload JSON reports ✅ How to parse JSON and display summaries ✅ How to use custom thresholds ✅ How to test exit code behavior ✅ How to separate source/test standards ✅ How to make checks informational vs blocking Testing: - ✅ Exit code 3 returned for critical disharmony - ✅ JSON output is valid and parseable - ✅ All 20 tests still pass - ✅ Black formatting maintained - ✅ Stderr message doesn't break JSON Integration Patterns Demonstrated: - Basic: Just add `harmonizer src/**/*.py` to CI - Standard: Fail on high/critical, pass on low/medium - Strict: Use custom threshold (0.3 for excellent) - Reporting: Generate JSON artifacts for analysis - Gradual: Start informational, then enforce This commit makes Python Code Harmonizer production-ready for any CI/CD platform. Teams can now enforce semantic code quality standards automatically. 💛⚓ Meta note: The tool found disharmony in its own code (main.py), showing it works! Functions like print_report and run_cli do more than their names suggest - a great example of the tool in action.
1 parent f2e309d commit 0d121fb

File tree

4 files changed

+792
-25
lines changed

4 files changed

+792
-25
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ jobs:
3939
- name: Test with pytest
4040
run: |
4141
pytest
42+
43+
- name: Check Code Harmony
44+
run: |
45+
# v1.2+: Harmony check with automatic exit codes
46+
# Fails build if critical disharmony detected
47+
harmonizer src/**/*.py

.github/workflows/harmony-check.yml

Lines changed: 159 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches: [ main, develop ]
88

99
jobs:
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

Comments
 (0)