|
| 1 | +name: "Code Functionality and Documentation Review" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + types: [opened, synchronize, reopened] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + issues: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + functionality-check: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@main |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@main |
| 26 | + with: |
| 27 | + node-version: '20' |
| 28 | + continue-on-error: true |
| 29 | + |
| 30 | + - name: Setup Python |
| 31 | + uses: actions/setup-python@main |
| 32 | + with: |
| 33 | + python-version: '3.11' |
| 34 | + continue-on-error: true |
| 35 | + |
| 36 | + - name: Setup Go |
| 37 | + uses: actions/setup-go@main |
| 38 | + with: |
| 39 | + go-version: 'stable' |
| 40 | + continue-on-error: true |
| 41 | + |
| 42 | + - name: Install Dependencies and Build |
| 43 | + id: build |
| 44 | + run: | |
| 45 | + echo "BUILD_STATUS=unknown" >> $GITHUB_OUTPUT |
| 46 | + |
| 47 | + # Node.js project |
| 48 | + if [ -f "package.json" ]; then |
| 49 | + echo "Detected Node.js project" |
| 50 | + npm install || echo "npm install failed" |
| 51 | + |
| 52 | + if grep -q '"build"' package.json; then |
| 53 | + npm run build && echo "BUILD_STATUS=success" >> $GITHUB_OUTPUT || echo "BUILD_STATUS=failed" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "BUILD_STATUS=no-build-script" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | + fi |
| 58 | + |
| 59 | + # Python project |
| 60 | + if [ -f "requirements.txt" ] || [ -f "setup.py" ] || [ -f "pyproject.toml" ]; then |
| 61 | + echo "Detected Python project" |
| 62 | + if [ -f "requirements.txt" ]; then |
| 63 | + pip install -r requirements.txt || echo "pip install failed" |
| 64 | + fi |
| 65 | + if [ -f "setup.py" ]; then |
| 66 | + pip install -e . || echo "setup.py install failed" |
| 67 | + fi |
| 68 | + echo "BUILD_STATUS=success" >> $GITHUB_OUTPUT |
| 69 | + fi |
| 70 | + |
| 71 | + # Go project |
| 72 | + if [ -f "go.mod" ]; then |
| 73 | + echo "Detected Go project" |
| 74 | + go build ./... && echo "BUILD_STATUS=success" >> $GITHUB_OUTPUT || echo "BUILD_STATUS=failed" >> $GITHUB_OUTPUT |
| 75 | + fi |
| 76 | + |
| 77 | + # Java/Maven project |
| 78 | + if [ -f "pom.xml" ]; then |
| 79 | + echo "Detected Maven project" |
| 80 | + mvn clean compile && echo "BUILD_STATUS=success" >> $GITHUB_OUTPUT || echo "BUILD_STATUS=failed" >> $GITHUB_OUTPUT |
| 81 | + fi |
| 82 | + |
| 83 | + # Gradle project |
| 84 | + if [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then |
| 85 | + echo "Detected Gradle project" |
| 86 | + ./gradlew build -x test && echo "BUILD_STATUS=success" >> $GITHUB_OUTPUT || echo "BUILD_STATUS=failed" >> $GITHUB_OUTPUT |
| 87 | + fi |
| 88 | + continue-on-error: true |
| 89 | + |
| 90 | + - name: Run Basic Functionality Tests |
| 91 | + run: | |
| 92 | + # Try to run tests if they exist |
| 93 | + if [ -f "package.json" ] && grep -q '"test"' package.json; then |
| 94 | + npm test || echo "Tests failed or not configured" |
| 95 | + fi |
| 96 | + |
| 97 | + if [ -f "pytest.ini" ] || [ -d "tests" ]; then |
| 98 | + pytest || echo "Pytest tests failed or not configured" |
| 99 | + fi |
| 100 | + |
| 101 | + if [ -f "go.mod" ]; then |
| 102 | + go test ./... || echo "Go tests failed or not configured" |
| 103 | + fi |
| 104 | + continue-on-error: true |
| 105 | + |
| 106 | + documentation-review: |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - name: Checkout code |
| 110 | + uses: actions/checkout@main |
| 111 | + |
| 112 | + - name: Analyze Documentation |
| 113 | + id: doc-analysis |
| 114 | + run: | |
| 115 | + echo "## Documentation Analysis" > /tmp/doc-analysis.md |
| 116 | + echo "" >> /tmp/doc-analysis.md |
| 117 | + |
| 118 | + # Check for main documentation files |
| 119 | + echo "### Main Documentation Files:" >> /tmp/doc-analysis.md |
| 120 | + for doc in README.md CONTRIBUTING.md LICENSE.md CHANGELOG.md CODE_OF_CONDUCT.md SECURITY.md; do |
| 121 | + if [ -f "$doc" ]; then |
| 122 | + echo "✅ $doc exists" >> /tmp/doc-analysis.md |
| 123 | + else |
| 124 | + echo "❌ $doc is missing" >> /tmp/doc-analysis.md |
| 125 | + fi |
| 126 | + done |
| 127 | + |
| 128 | + echo "" >> /tmp/doc-analysis.md |
| 129 | + echo "### README.md Quality Check:" >> /tmp/doc-analysis.md |
| 130 | + |
| 131 | + if [ -f "README.md" ]; then |
| 132 | + word_count=$(wc -w < README.md) |
| 133 | + echo "- Word count: $word_count" >> /tmp/doc-analysis.md |
| 134 | + |
| 135 | + if [ $word_count -lt 50 ]; then |
| 136 | + echo "⚠️ README.md is very short (< 50 words)" >> /tmp/doc-analysis.md |
| 137 | + else |
| 138 | + echo "✅ README.md has adequate content" >> /tmp/doc-analysis.md |
| 139 | + fi |
| 140 | + |
| 141 | + # Check for common sections |
| 142 | + for section in "Installation" "Usage" "Features" "Contributing" "License" "Documentation"; do |
| 143 | + if grep -qi "$section" README.md; then |
| 144 | + echo "✅ Contains '$section' section" >> /tmp/doc-analysis.md |
| 145 | + else |
| 146 | + echo "⚠️ Missing '$section' section" >> /tmp/doc-analysis.md |
| 147 | + fi |
| 148 | + done |
| 149 | + else |
| 150 | + echo "❌ README.md does not exist" >> /tmp/doc-analysis.md |
| 151 | + fi |
| 152 | + |
| 153 | + echo "" >> /tmp/doc-analysis.md |
| 154 | + echo "### Additional Documentation:" >> /tmp/doc-analysis.md |
| 155 | + |
| 156 | + # Find all markdown files |
| 157 | + find . -name "*.md" \ |
| 158 | + ! -path "*/node_modules/*" \ |
| 159 | + ! -path "*/.venv/*" \ |
| 160 | + ! -path "*/vendor/*" \ |
| 161 | + -type f | while read -r file; do |
| 162 | + echo "- $file" >> /tmp/doc-analysis.md |
| 163 | + done || echo "No additional markdown files found" >> /tmp/doc-analysis.md |
| 164 | + |
| 165 | + echo "" >> /tmp/doc-analysis.md |
| 166 | + echo "### Code with Missing Documentation:" >> /tmp/doc-analysis.md |
| 167 | + |
| 168 | + # Check for undocumented functions/classes (basic heuristic) |
| 169 | + # Python |
| 170 | + if find . -name "*.py" ! -path "*/.venv/*" ! -path "*/node_modules/*" | grep -q .; then |
| 171 | + echo "" >> /tmp/doc-analysis.md |
| 172 | + echo "#### Python files:" >> /tmp/doc-analysis.md |
| 173 | + find . -name "*.py" \ |
| 174 | + ! -path "*/.venv/*" \ |
| 175 | + ! -path "*/node_modules/*" \ |
| 176 | + ! -path "*/dist/*" \ |
| 177 | + ! -name "__init__.py" \ |
| 178 | + -type f | while read -r file; do |
| 179 | + # Count functions and classes |
| 180 | + func_count=$(grep -c "^def " "$file" 2>/dev/null || echo 0) |
| 181 | + class_count=$(grep -c "^class " "$file" 2>/dev/null || echo 0) |
| 182 | + docstring_count=$(grep -c '"""' "$file" 2>/dev/null || echo 0) |
| 183 | + |
| 184 | + total=$((func_count + class_count)) |
| 185 | + if [ $total -gt 0 ] && [ $docstring_count -eq 0 ]; then |
| 186 | + echo "⚠️ $file: $total definitions, no docstrings" >> /tmp/doc-analysis.md |
| 187 | + fi |
| 188 | + done |
| 189 | + fi |
| 190 | + |
| 191 | + # JavaScript/TypeScript |
| 192 | + if find . \( -name "*.js" -o -name "*.ts" \) ! -path "*/node_modules/*" ! -path "*/dist/*" | grep -q .; then |
| 193 | + echo "" >> /tmp/doc-analysis.md |
| 194 | + echo "#### JavaScript/TypeScript files:" >> /tmp/doc-analysis.md |
| 195 | + find . \( -name "*.js" -o -name "*.ts" \) \ |
| 196 | + ! -path "*/node_modules/*" \ |
| 197 | + ! -path "*/dist/*" \ |
| 198 | + ! -path "*/build/*" \ |
| 199 | + -type f | while read -r file; do |
| 200 | + # Count functions and classes |
| 201 | + func_count=$(grep -cE "(^function |^export function |^const .* = .*=>)" "$file" 2>/dev/null || echo 0) |
| 202 | + class_count=$(grep -c "^class " "$file" 2>/dev/null || echo 0) |
| 203 | + jsdoc_count=$(grep -c '/\*\*' "$file" 2>/dev/null || echo 0) |
| 204 | + |
| 205 | + total=$((func_count + class_count)) |
| 206 | + if [ $total -gt 5 ] && [ $jsdoc_count -eq 0 ]; then |
| 207 | + echo "⚠️ $file: ~$total definitions, no JSDoc comments" >> /tmp/doc-analysis.md |
| 208 | + fi |
| 209 | + done |
| 210 | + fi |
| 211 | + |
| 212 | + cat /tmp/doc-analysis.md |
| 213 | +
|
| 214 | + - name: GitHub Copilot Documentation Review |
| 215 | + uses: github/copilot-cli-actions@v1 |
| 216 | + with: |
| 217 | + query: | |
| 218 | + Review the documentation for this repository: |
| 219 | + 1. Check README.md completeness and quality |
| 220 | + 2. Verify all features and functionality are documented |
| 221 | + 3. Check for installation and usage instructions |
| 222 | + 4. Identify missing or outdated documentation |
| 223 | + 5. Suggest improvements for clarity and completeness |
| 224 | + 6. Verify code comments and inline documentation |
| 225 | + 7. Check for API documentation if applicable |
| 226 | + 8. Ensure contributing guidelines are present |
| 227 | + |
| 228 | + Provide specific recommendations with file names and sections. |
| 229 | + env: |
| 230 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 231 | + continue-on-error: true |
| 232 | + |
| 233 | + - name: Create Documentation Review Report |
| 234 | + uses: actions/github-script@main |
| 235 | + with: |
| 236 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 237 | + script: | |
| 238 | + const fs = require('fs'); |
| 239 | + const analysis = fs.readFileSync('/tmp/doc-analysis.md', 'utf8'); |
| 240 | + |
| 241 | + const date = new Date().toISOString().split('T')[0]; |
| 242 | + const title = `Code Functionality & Documentation Review - ${date}`; |
| 243 | + |
| 244 | + const buildStatus = process.env.BUILD_STATUS || 'unknown'; |
| 245 | + const buildEmoji = buildStatus === 'success' ? '✅' : |
| 246 | + buildStatus === 'failed' ? '❌' : '⚠️'; |
| 247 | + |
| 248 | + const body = `# Code Functionality and Documentation Review |
| 249 | + |
| 250 | + ## Build Status: ${buildEmoji} ${buildStatus} |
| 251 | + |
| 252 | + ${analysis} |
| 253 | + |
| 254 | + ## Functionality Review |
| 255 | + |
| 256 | + - Build status: ${buildStatus} |
| 257 | + - Tests execution: See workflow logs for details |
| 258 | + |
| 259 | + ## Recommendations |
| 260 | + |
| 261 | + ### Documentation: |
| 262 | + 1. **Complete README.md** with all required sections |
| 263 | + 2. **Add missing documentation files** (CONTRIBUTING.md, CHANGELOG.md, etc.) |
| 264 | + 3. **Document all public APIs** and exported functions |
| 265 | + 4. **Add inline code comments** for complex logic |
| 266 | + 5. **Create usage examples** and tutorials |
| 267 | + 6. **Update outdated documentation** to match current code |
| 268 | + |
| 269 | + ### Functionality: |
| 270 | + 1. **Ensure code builds successfully** in CI environment |
| 271 | + 2. **Fix any broken functionality** identified in tests |
| 272 | + 3. **Add error handling** and validation |
| 273 | + 4. **Verify all features work as documented** |
| 274 | + |
| 275 | + ## Action Items |
| 276 | + |
| 277 | + - [ ] Add/update missing documentation files |
| 278 | + - [ ] Improve README.md quality and completeness |
| 279 | + - [ ] Add code comments and docstrings |
| 280 | + - [ ] Fix build issues if any |
| 281 | + - [ ] Verify all features are documented |
| 282 | + |
| 283 | + --- |
| 284 | + *This issue was automatically generated by the Functionality & Documentation Review workflow.* |
| 285 | + `; |
| 286 | + |
| 287 | + // Check for existing issues |
| 288 | + const issues = await github.rest.issues.listForRepo({ |
| 289 | + owner: context.repo.owner, |
| 290 | + repo: context.repo.repo, |
| 291 | + state: 'open', |
| 292 | + labels: ['documentation', 'automated'], |
| 293 | + per_page: 10 |
| 294 | + }); |
| 295 | + |
| 296 | + const recentIssue = issues.data.find(issue => { |
| 297 | + const createdAt = new Date(issue.created_at); |
| 298 | + const daysSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60 * 24); |
| 299 | + return daysSinceCreation < 7; |
| 300 | + }); |
| 301 | + |
| 302 | + if (recentIssue) { |
| 303 | + console.log(`Recent issue found: #${recentIssue.number}, updating`); |
| 304 | + await github.rest.issues.createComment({ |
| 305 | + owner: context.repo.owner, |
| 306 | + repo: context.repo.repo, |
| 307 | + issue_number: recentIssue.number, |
| 308 | + body: `## Updated Analysis (${date})\n\nBuild Status: ${buildEmoji} ${buildStatus}\n\n${analysis}` |
| 309 | + }); |
| 310 | + } else { |
| 311 | + await github.rest.issues.create({ |
| 312 | + owner: context.repo.owner, |
| 313 | + repo: context.repo.repo, |
| 314 | + title: title, |
| 315 | + body: body, |
| 316 | + labels: ['documentation', 'functionality', 'automated', 'needs-review'] |
| 317 | + }); |
| 318 | + } |
| 319 | + env: |
| 320 | + BUILD_STATUS: ${{ steps.build.outputs.BUILD_STATUS }} |
0 commit comments