name: Code Quality on: pull_request: types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: code-quality: runs-on: self-hosted name: Code Quality Checks steps: - name: Checkout code uses: https://code.forgejo.org/actions/checkout@v4 with: fetch-depth: 0 # Full history for better analysis - name: Setup Node.js run: | node --version npm --version - name: Install dependencies run: npm ci - name: Check code complexity run: | echo "Analyzing code complexity..." npx -y complexity-report src/**/*.ts src/**/*.js --format json > complexity.json || true node -e " try { const report = JSON.parse(require('fs').readFileSync('complexity.json', 'utf8')); console.log('\\nšŸ“Š Code Complexity Report:'); const files = report.reports || []; const complex = files.filter(f => f.aggregate?.cyclomatic > 10); if (complex.length > 0) { console.log('\\nāš ļø Files with high complexity (>10):'); complex.forEach(f => { console.log(\` - \${f.path}: Cyclomatic complexity = \${f.aggregate.cyclomatic}\`); }); } else { console.log('āœ… All files have acceptable complexity'); } } catch (e) { console.log('ā„¹ļø Complexity analysis not available'); } " - name: Check for console.log statements run: | echo "Checking for console.log statements..." FILES=$(find src/ -name "*.ts" -o -name "*.js" | xargs grep -l "console\.log" || true) if [ -n "$FILES" ]; then echo "āš ļø Found console.log statements (consider using proper logging):" echo "$FILES" else echo "āœ… No console.log statements in source code" fi - name: Check for TODO/FIXME comments run: | echo "Checking for TODO/FIXME comments..." TODOS=$(find . -name "*.ts" -o -name "*.js" | grep -v node_modules | grep -v dist | xargs grep -l "TODO\|FIXME\|HACK\|XXX" || true) if [ -n "$TODOS" ]; then echo "šŸ“ Found TODO/FIXME comments:" echo "$TODOS" echo "" echo "ā„¹ļø Consider creating issues for these items" else echo "āœ… No TODO/FIXME comments found" fi - name: Check for large files run: | echo "Checking for large files..." # Use du to find files larger than 1MB (1024KB) LARGE_FILES=$(find . -type f \ -not -path "./node_modules/*" \ -not -path "./.git/*" \ -not -path "./dist/*" \ -not -path "./coverage/*" \ -not -name "*.db" \ -not -name "package-lock.json" \ -exec sh -c 'size=$(du -k "$1" 2>/dev/null | cut -f1); [ "$size" -gt 1024 ] && echo "$1"' _ {} \;) if [ -n "$LARGE_FILES" ]; then echo "āš ļø Found large files (>1MB):" echo "$LARGE_FILES" | xargs -I {} sh -c 'echo " - {} ($(du -h {} | cut -f1))"' echo "" echo "Consider if these files should be in the repository" else echo "āœ… No large files detected" fi - name: Check TypeScript strict mode run: | echo "Verifying TypeScript strict mode..." STRICT=$(grep -E '"strict":\s*true' tsconfig.json) if [ -n "$STRICT" ]; then echo "āœ… TypeScript strict mode is enabled" else echo "āš ļø Consider enabling TypeScript strict mode for better type safety" fi - name: Analyze import statements run: | echo "Analyzing imports..." # Check for circular dependencies npx -y madge --circular --extensions ts,js src/ || true # Check for unused exports echo "" echo "Checking for potentially unused exports..." npx -y ts-unused-exports tsconfig.json --excludePathsFromReport=src/types || true - name: Generate PR comment if: always() run: | echo "## šŸ” Code Quality Report" > pr-comment.md echo "" >> pr-comment.md echo "All automated code quality checks have been run. Please review the logs above for details." >> pr-comment.md echo "" >> pr-comment.md echo "### Checklist" >> pr-comment.md echo "- [ ] ESLint passes" >> pr-comment.md echo "- [ ] TypeScript compiles without errors" >> pr-comment.md echo "- [ ] Tests pass" >> pr-comment.md echo "- [ ] No high complexity code" >> pr-comment.md echo "- [ ] No hardcoded secrets" >> pr-comment.md echo "" >> pr-comment.md echo "_This comment was generated automatically by the Code Quality workflow._" >> pr-comment.md