1+ name : ' Code Quality Checks'
2+ description : ' Run comprehensive code quality checks including formatting, linting, and test validation'
3+ author : ' CodePrism Team'
4+
5+ inputs :
6+ rust-toolchain :
7+ description : ' Rust toolchain to use for checks'
8+ required : false
9+ default : ' stable'
10+ working-directory :
11+ description : ' Working directory for quality checks'
12+ required : false
13+ default : ' .'
14+ fail-fast :
15+ description : ' Whether to fail fast on first error'
16+ required : false
17+ default : ' false'
18+ clippy-args :
19+ description : ' Additional arguments for clippy'
20+ required : false
21+ default : ' --all-features --all-targets --workspace -- -D warnings'
22+ test-theater-check :
23+ description : ' Whether to run test theater detection'
24+ required : false
25+ default : ' true'
26+
27+ outputs :
28+ fmt-status :
29+ description : ' Formatting check status (passed/failed)'
30+ value : ${{ steps.fmt-check.outputs.status }}
31+ clippy-status :
32+ description : ' Clippy check status (passed/failed)'
33+ value : ${{ steps.clippy-check.outputs.status }}
34+ test-theater-status :
35+ description : ' Test theater check status (passed/failed)'
36+ value : ${{ steps.test-theater.outputs.status }}
37+
38+ runs :
39+ using : ' composite'
40+ steps :
41+ - name : Check Rust formatting
42+ id : fmt-check
43+ shell : bash
44+ working-directory : ${{ inputs.working-directory }}
45+ run : |
46+ echo "=== Running Rust Formatting Check ==="
47+ if cargo fmt --all -- --check; then
48+ echo "✅ Formatting check passed"
49+ echo "status=passed" >> $GITHUB_OUTPUT
50+ else
51+ echo "❌ Formatting check failed"
52+ echo "status=failed" >> $GITHUB_OUTPUT
53+ if [[ "${{ inputs.fail-fast }}" == "true" ]]; then
54+ exit 1
55+ fi
56+ fi
57+
58+ - name : Run Clippy linting
59+ id : clippy-check
60+ shell : bash
61+ working-directory : ${{ inputs.working-directory }}
62+ run : |
63+ echo "=== Running Clippy Linting ==="
64+ echo "Clippy arguments: ${{ inputs.clippy-args }}"
65+ if cargo clippy ${{ inputs.clippy-args }}; then
66+ echo "✅ Clippy check passed"
67+ echo "status=passed" >> $GITHUB_OUTPUT
68+ else
69+ echo "❌ Clippy check failed"
70+ echo "status=failed" >> $GITHUB_OUTPUT
71+ if [[ "${{ inputs.fail-fast }}" == "true" ]]; then
72+ exit 1
73+ fi
74+ fi
75+
76+ - name : Check for test theater
77+ id : test-theater
78+ if : inputs.test-theater-check == 'true'
79+ shell : bash
80+ working-directory : ${{ inputs.working-directory }}
81+ run : |
82+ echo "=== Running Test Theater Detection ==="
83+
84+ # Check if the detection script exists
85+ if [[ -f "scripts/detect-test-theater.py" ]]; then
86+ echo "Running test theater detection script..."
87+ if python scripts/detect-test-theater.py; then
88+ echo "✅ No test theater detected"
89+ echo "status=passed" >> $GITHUB_OUTPUT
90+ else
91+ echo "❌ Test theater patterns detected"
92+ echo "status=failed" >> $GITHUB_OUTPUT
93+ if [[ "${{ inputs.fail-fast }}" == "true" ]]; then
94+ exit 1
95+ fi
96+ fi
97+ else
98+ echo "⚠️ Test theater detection script not found, running basic checks..."
99+
100+ # Basic test theater detection patterns
101+ theater_patterns=(
102+ "assert!(true)"
103+ "assert_eq!(true, true)"
104+ "// TODO.*test"
105+ "fn test.*{ *}"
106+ "\.unwrap\(\).*// Test"
107+ )
108+
109+ theater_found=false
110+ for pattern in "${theater_patterns[@]}"; do
111+ if grep -r "$pattern" tests/ src/ 2>/dev/null | grep -v ".git" | head -5; then
112+ echo "❌ Potential test theater pattern found: $pattern"
113+ theater_found=true
114+ fi
115+ done
116+
117+ if [[ "$theater_found" == "true" ]]; then
118+ echo "❌ Test theater patterns detected"
119+ echo "status=failed" >> $GITHUB_OUTPUT
120+ if [[ "${{ inputs.fail-fast }}" == "true" ]]; then
121+ exit 1
122+ fi
123+ else
124+ echo "✅ No obvious test theater patterns found"
125+ echo "status=passed" >> $GITHUB_OUTPUT
126+ fi
127+ fi
128+
129+ - name : Run additional quality checks
130+ shell : bash
131+ working-directory : ${{ inputs.working-directory }}
132+ run : |
133+ echo "=== Running Additional Quality Checks ==="
134+
135+ # Check for common code smells
136+ echo "Checking for potential code smells..."
137+
138+ # Check for excessive use of unwrap()
139+ unwrap_count=$(grep -r "\.unwrap()" src/ 2>/dev/null | wc -l || echo "0")
140+ if [[ $unwrap_count -gt 10 ]]; then
141+ echo "⚠️ Warning: Found $unwrap_count uses of .unwrap() - consider using proper error handling"
142+ else
143+ echo "✅ Appropriate use of .unwrap() ($unwrap_count occurrences)"
144+ fi
145+
146+ # Check for TODO/FIXME comments
147+ todo_count=$(grep -r "TODO\|FIXME" src/ 2>/dev/null | wc -l || echo "0")
148+ if [[ $todo_count -gt 0 ]]; then
149+ echo "ℹ️ Found $todo_count TODO/FIXME comments:"
150+ grep -rn "TODO\|FIXME" src/ 2>/dev/null | head -5
151+ else
152+ echo "✅ No TODO/FIXME comments found"
153+ fi
154+
155+ # Check for large functions (basic heuristic)
156+ echo "Checking for potentially large functions..."
157+ large_funcs=$(grep -A 100 "^fn " src/**/*.rs 2>/dev/null | grep -c "^fn " || echo "0")
158+ echo "ℹ️ Functions analyzed: $large_funcs"
159+
160+ - name : Quality summary
161+ shell : bash
162+ run : |
163+ echo "=== Quality Checks Summary ==="
164+ echo "Formatting: ${{ steps.fmt-check.outputs.status }}"
165+ echo "Clippy: ${{ steps.clippy-check.outputs.status }}"
166+ if [[ "${{ inputs.test-theater-check }}" == "true" ]]; then
167+ echo "Test Theater: ${{ steps.test-theater.outputs.status }}"
168+ fi
169+
170+ # Determine overall status
171+ overall_status="passed"
172+ if [[ "${{ steps.fmt-check.outputs.status }}" == "failed" ]] || \
173+ [[ "${{ steps.clippy-check.outputs.status }}" == "failed" ]] || \
174+ [[ "${{ steps.test-theater.outputs.status }}" == "failed" ]]; then
175+ overall_status="failed"
176+ fi
177+
178+ if [[ "$overall_status" == "passed" ]]; then
179+ echo "🎉 All quality checks passed!"
180+ else
181+ echo "❌ Some quality checks failed"
182+ if [[ "${{ inputs.fail-fast }}" == "true" ]]; then
183+ exit 1
184+ fi
185+ fi
0 commit comments