name: π― Code Quality
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run daily at 06:00 UTC
- cron: '0 6 * * *'
jobs:
# π Frontend Code Quality
frontend-quality:
name: π¨ Frontend Quality
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
- name: π§ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: π¦ Install dependencies
run: |
cd frontend
npm ci
- name: π§Ή ESLint
run: |
cd frontend
npm run lint -- --max-warnings 0
- name: π TypeScript strict check
run: |
cd frontend
npx tsc --noEmit --strict
- name: π Code formatting check
run: |
cd frontend
npx prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}"
- name: π Bundle size check
run: |
cd frontend
npm run build
npx bundlesize --files "dist/static/js/*.js" --max-size "500kB"
- name: π Lighthouse performance check
run: |
cd frontend
npm run build
npx lhci autorun --config=lighthouserc.json || true
- name: π€ Upload Lighthouse results
uses: actions/upload-artifact@v4
if: always()
with:
name: lighthouse-results
path: frontend/.lighthouseci/
# π Backend Code Quality
backend-quality:
name: π Backend Quality
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
- name: π§ Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: π¦ Install dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install flake8 black isort mypy bandit safety pytest pytest-cov
- name: π§Ή Code formatting (Black)
run: |
cd backend
black --check --diff .
- name: π Import sorting (isort)
run: |
cd backend
isort --check-only --diff .
- name: π Linting (flake8)
run: |
cd backend
flake8 . --count --statistics --max-complexity=10 --max-line-length=88
- name: π Type checking (mypy)
run: |
cd backend
mypy . --ignore-missing-imports --no-strict-optional
- name: π Security scanning (bandit)
run: |
cd backend
bandit -r . -f json -o bandit-report.json || true
- name: π§ͺ Test coverage check
run: |
cd backend
python -m pytest --cov=app --cov-report=xml --cov-fail-under=80
- name: π€ Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: backend-coverage
path: backend/coverage.xml
- name: π€ Upload security reports
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports
path: backend/bandit-report.json
# π Documentation Quality
docs-quality:
name: π Documentation Quality
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
- name: π§ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: π Check documentation formatting
run: |
npm install -g markdownlint-cli
markdownlint "**/*.md" --config .markdownlint.json || true
- name: π Check documentation links
run: |
npm install -g markdown-link-check
find docs -name "*.md" -exec markdown-link-check {} \; || true
- name: π Check documentation coverage
run: |
# Count documented functions vs total functions
cd frontend
npx jsdoc -r src -d /tmp/docs-frontend --readme README.md
cd ../backend
python -m pydoc -w . 2>/dev/null || true
# Basic coverage check
echo "Documentation check completed"
# π Quality Gate
quality-gate:
name: πͺ Quality Gate
runs-on: ubuntu-latest
needs: [frontend-quality, backend-quality, docs-quality]
if: always()
steps:
- name: π Evaluate quality results
run: |
# Check if all quality jobs passed
if [ "${{ needs.frontend-quality.result }}" = "success" ] && \
[ "${{ needs.backend-quality.result }}" = "success" ] && \
[ "${{ needs.docs-quality.result }}" = "success" ]; then
echo "β
All quality checks passed"
echo "quality-gate=passed" >> $GITHUB_OUTPUT
else
echo "β Some quality checks failed"
echo "quality-gate=failed" >> $GITHUB_OUTPUT
exit 1
fi
- name: π Generate quality report
run: |
echo "# π― Code Quality Report" > quality-report.md
echo "" >> quality-report.md
echo "## Results" >> quality-report.md
echo "- **Frontend Quality**: ${{ needs.frontend-quality.result }}" >> quality-report.md
echo "- **Backend Quality**: ${{ needs.backend-quality.result }}" >> quality-report.md
echo "- **Documentation Quality**: ${{ needs.docs-quality.result }}" >> quality-report.md
echo "" >> quality-report.md
echo "**Generated:** $(date)" >> quality-report.md
- name: π€ Upload quality report
uses: actions/upload-artifact@v4
with:
name: quality-report
path: quality-report.md
- name: π’ Notify quality issues
uses: 8398a7/action-slack@v3
if: failure()
with:
status: failure
text: "Code quality checks failed - please review and fix issues"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}