Lectures
: Create lecture series
#1984
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java Code Quality Analysis | |
on: | |
push: | |
branches: [ develop ] | |
paths: | |
- src/main/java/** | |
pull_request: | |
paths: | |
- src/main/java/** | |
jobs: | |
code-quality-analysis: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v5 | |
- name: Set up Python | |
uses: actions/setup-python@v6 | |
with: | |
python-version: '3.13' | |
- name: Check LOC and number of class dependencies | |
run: | | |
# Run the analysis and capture output | |
output=$(python supporting_scripts/analyze_java_files.py) | |
echo "$output" | |
echo "" | |
# Extract violation counts | |
large_classes=$(echo "$output" | grep -o "Found [0-9]* classes with more than" | grep -o "[0-9]*") | |
complex_beans=$(echo "$output" | grep -o "Found [0-9]* Spring beans with constructors having more than" | grep -o "[0-9]*") | |
# TODO these values should become zero in the future | |
max_large_classes=9 | |
max_complex_beans=9 | |
echo "==========================================" | |
echo "CODE QUALITY ANALYSIS SUMMARY" | |
echo "==========================================" | |
echo "Large classes found: $large_classes (max allowed: $max_large_classes)" | |
echo "Complex beans found: $complex_beans (max allowed: $max_complex_beans)" | |
echo "" | |
violations=0 | |
large_class_violation=false | |
complex_bean_violation=false | |
if [ "$large_classes" -gt "$max_large_classes" ]; then | |
echo "❌ Too many large classes: $large_classes > $max_large_classes" | |
large_class_violation=true | |
else | |
echo "✅ Large classes within threshold: $large_classes <= $max_large_classes" | |
fi | |
if [ "$complex_beans" -gt "$max_complex_beans" ]; then | |
excess_complex_beans=$((complex_beans - max_complex_beans)) | |
echo "❌ Too many complex beans: $complex_beans > $max_complex_beans ($excess_complex_beans beans need to be refactored)" | |
complex_bean_violation=true | |
else | |
echo "✅ Complex beans within threshold: $complex_beans <= $max_complex_beans" | |
fi | |
echo "==========================================" | |
if [ $large_class_violation = "true" ] || [ $complex_bean_violation = "true" ]; then | |
echo "::error::Code quality check failed" | |
echo "" | |
if [ "$large_class_violation" = true ]; then | |
echo "VIOLATING LARGE CLASSES ($large_classes classes):" | |
echo "------------------------------------------------" | |
violating_classes=$(echo "$output" | sed -n '/Found [0-9]* classes with more than/,/Found [0-9]* Spring beans/p' | grep -E '\.java: [0-9]+ lines') | |
echo "$violating_classes" | |
echo "" | |
fi | |
if [ "$complex_bean_violation" = true ]; then | |
echo "VIOLATING COMPLEX BEANS ($complex_beans beans):" | |
echo "-----------------------------------------------" | |
violating_beans=$(echo "$output" | sed -n '/Found [0-9]* Spring beans with constructors having more than/,$p' | grep -E '\.java: [0-9]+ parameters') | |
echo "$violating_beans" | |
echo "" | |
fi | |
echo "Please refactor the classes listed above to meet the code quality standards!" | |
exit 1 | |
else | |
echo "✅ Code quality check passed" | |
fi |