-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (74 loc) · 2.5 KB
/
code-quality.yml
File metadata and controls
88 lines (74 loc) · 2.5 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
name: Code Quality Checks
on:
pull_request:
branches: [ main, develop ]
push:
branches: [ main, develop ]
permissions:
contents: read
pull-requests: write
jobs:
code-quality:
name: Code Quality Analysis
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"
cache: 'pip'
- name: Install code quality tools
run: |
python -m pip install --upgrade pip
pip install --quiet \
black>=23.0.0 \
isort>=5.13.0 \
flake8>=6.0.0 \
pylint>=3.0.0 \
mypy>=1.5.0 \
types-requests \
types-PyYAML
- name: Check code formatting with Black
run: |
black --check --diff app/ tests/ cli.py main.py
- name: Check import sorting with isort
run: |
isort --check-only --diff app/ tests/ cli.py main.py
- name: Lint with flake8
run: |
flake8 app/ tests/ cli.py main.py
- name: Type check with mypy
run: |
mypy app/ --config-file mypy.ini
- name: Run pylint (informational)
run: |
pylint app/ --disable=all --enable=E,F --max-line-length=120 || true
continue-on-error: true
- name: Check code complexity
run: |
echo "Checking code complexity..."
# Count functions/methods with high complexity
COMPLEX_FUNCTIONS=$(find app/ -name "*.py" -exec grep -l "def " {} \; | xargs -I {} python3 -c "
import ast
import sys
try:
with open('{}', 'r') as f:
tree = ast.parse(f.read())
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
complexity = len([n for n in ast.walk(node) if isinstance(n, (ast.If, ast.While, ast.For, ast.AsyncFor, ast.Try, ast.With, ast.AsyncWith))])
if complexity > 15:
print(f'{}: {node.name} has complexity {complexity}')
except:
pass
" || true)
if [ -n "$COMPLEX_FUNCTIONS" ]; then
echo "⚠️ Functions with high complexity detected:"
echo "$COMPLEX_FUNCTIONS"
echo "Consider refactoring to reduce complexity."
else
echo "✅ No overly complex functions detected"
fi
continue-on-error: true