name: Pylint Code Quality
on:
push:
branches: [ main, develop ]
paths:
- 'src/**/*.py'
- 'tests/**/*.py'
- '.pylintrc'
- 'requirements.txt'
pull_request:
branches: [ main ]
paths:
- 'src/**/*.py'
- 'tests/**/*.py'
- '.pylintrc'
- 'requirements.txt'
jobs:
pylint:
name: Pylint Analysis
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Analyze code with Pylint
run: |
echo "🔍 Running Pylint analysis..."
pylint src/ --rcfile=.pylintrc --output-format=github
echo "✅ Pylint analysis completed successfully!"
- name: Generate Pylint report
if: always()
run: |
echo "📊 Generating detailed Pylint reports..."
pylint src/ --rcfile=.pylintrc --output-format=json > pylint-report-${{ matrix.python-version }}.json || true
pylint src/ --rcfile=.pylintrc --output-format=text > pylint-report-${{ matrix.python-version }}.txt || true
# Display score in logs
if [ -f "pylint-report-${{ matrix.python-version }}.txt" ]; then
echo "📈 Pylint Score for Python ${{ matrix.python-version }}:"
grep "Your code has been rated at" pylint-report-${{ matrix.python-version }}.txt || echo "Score not found"
fi
- name: Upload Pylint reports
if: always()
uses: actions/upload-artifact@v5
with:
name: pylint-reports-python-${{ matrix.python-version }}
path: |
pylint-report-${{ matrix.python-version }}.json
pylint-report-${{ matrix.python-version }}.txt
quality-gate:
name: Quality Gate
runs-on: ubuntu-latest
needs: pylint
if: always()
steps:
- name: Check Pylint results
run: |
if [[ "${{ needs.pylint.result }}" == "failure" ]]; then
echo "❌ Pylint quality gate failed"
echo "Code quality standards not met. Please fix pylint issues before merging."
exit 1
else
echo "✅ Pylint quality gate passed"
echo "Code meets quality standards!"
fi