|
| 1 | +name: Documentation Review |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "**.lua" |
| 8 | + - ".github/**" |
| 9 | + - "plugin/**" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + review-docs: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Fetch full history to analyze changes |
| 23 | + persist-credentials: true |
| 24 | + |
| 25 | + - name: Run Claude Code to review documentation |
| 26 | + id: claude-review |
| 27 | + uses: anthropics/claude-code-action@8b9d5bb25a638c9aa5103496c0139d99b4936d42 # beta |
| 28 | + with: |
| 29 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 30 | + prompt: | |
| 31 | + As a Documentation Validator, your task is to review the current code in this repository and ensure that the markdown documentation files (README.md, ARCHITECTURE.md, and DEVELOPMENT.md) are up-to-date and accurate. |
| 32 | +
|
| 33 | + Focus on these specific areas: |
| 34 | + 1. Configuration options - Ensure all config options in lua/claudecode/config.lua are accurately reflected in README.md |
| 35 | + 2. Commands and usage - Verify all commands and keymaps mentioned in plugin/claudecode.lua are correctly documented in README.md |
| 36 | + 3. Architecture details - Validate the module structure in ARCHITECTURE.md matches the actual codebase structure |
| 37 | + 4. Development status - Review the implementation status in DEVELOPMENT.md against the actual codebase |
| 38 | + 5. Terminal feature - Check that the terminal integration is documented correctly across all files |
| 39 | +
|
| 40 | + For any inconsistencies found: |
| 41 | + 1. Note the specific issue (what's incorrect, missing, or outdated) |
| 42 | + 2. Provide the correct information based on the current codebase |
| 43 | + 3. Create a corrected version of the relevant section |
| 44 | +
|
| 45 | + Output your findings in this format: |
| 46 | + ```json |
| 47 | + { |
| 48 | + "review_date": "YYYY-MM-DD", |
| 49 | + "files_checked": ["README.md", "ARCHITECTURE.md", "DEVELOPMENT.md"], |
| 50 | + "issues_found": [ |
| 51 | + { |
| 52 | + "file": "path/to/file.md", |
| 53 | + "section": "Section title", |
| 54 | + "issue": "Description of inconsistency", |
| 55 | + "corrected_content": "The corrected markdown content" |
| 56 | + } |
| 57 | + ] |
| 58 | + } |
| 59 | + ``` |
| 60 | +
|
| 61 | + If no issues are found, return an empty "issues_found" array. |
| 62 | +
|
| 63 | + - name: Process documentation updates |
| 64 | + id: process-updates |
| 65 | + shell: bash |
| 66 | + # zizmor-disable-next-line template-injection |
| 67 | + env: |
| 68 | + CLAUDE_OUTPUT: ${{ steps.claude-review.outputs.result }} |
| 69 | + run: | |
| 70 | + # Extract issues from Claude's output |
| 71 | +
|
| 72 | + # Check if the output contains the expected JSON format |
| 73 | + if ! echo "$CLAUDE_OUTPUT" | grep -q "\"issues_found\""; then |
| 74 | + echo "No valid JSON output found from Claude review" |
| 75 | + exit 0 |
| 76 | + fi |
| 77 | +
|
| 78 | + # Extract the JSON part (between ```json and ```) |
| 79 | + echo "$CLAUDE_OUTPUT" | sed -n "/\`\`\`json/,/\`\`\`/p" | sed "1d;\$d" > json_output.txt |
| 80 | + echo "JSON output extracted" |
| 81 | +
|
| 82 | + # Parse the JSON and check if there are issues |
| 83 | + ISSUES_FOUND=$(jq ".issues_found | length" json_output.txt) |
| 84 | + echo "Issues found: $ISSUES_FOUND" |
| 85 | +
|
| 86 | + # Clean up json_output.txt if no issues are found or after processing |
| 87 | + if [ "$ISSUES_FOUND" -eq 0 ]; then |
| 88 | + echo "No documentation issues found" |
| 89 | + rm -f json_output.txt # Clean up if exiting early |
| 90 | + exit 0 |
| 91 | + fi |
| 92 | +
|
| 93 | + if [ "$ISSUES_FOUND" -eq 0 ]; then |
| 94 | + echo "No documentation issues found" |
| 95 | + exit 0 |
| 96 | + fi |
| 97 | +
|
| 98 | + echo "Found $ISSUES_FOUND documentation issues to fix" |
| 99 | + echo "issues_found=$ISSUES_FOUND" >> "$GITHUB_OUTPUT" |
| 100 | +
|
| 101 | + # Create a new branch for the fixes |
| 102 | + BRANCH_NAME="docs/update-$(date +%Y%m%d%H%M%S)" |
| 103 | + git checkout -b "$BRANCH_NAME" |
| 104 | +
|
| 105 | + # Apply each correction - use a safer approach |
| 106 | + for i in $(seq 0 $((ISSUES_FOUND - 1))); do |
| 107 | + # Extract each field safely into separate files |
| 108 | + jq -r ".issues_found[$i].file" json_output.txt > issue_file.txt |
| 109 | + jq -r ".issues_found[$i].section" json_output.txt > issue_section.txt |
| 110 | + jq -r ".issues_found[$i].issue" json_output.txt > issue_desc.txt |
| 111 | + jq -r ".issues_found[$i].corrected_content" json_output.txt > issue_content.txt |
| 112 | +
|
| 113 | + # Read from files |
| 114 | + FILE=$(cat issue_file.txt) |
| 115 | + SECTION=$(cat issue_section.txt) |
| 116 | + ISSUE=$(cat issue_desc.txt) |
| 117 | + CONTENT=$(cat issue_content.txt) |
| 118 | +
|
| 119 | + echo "Updating $FILE - Section: $SECTION" |
| 120 | +
|
| 121 | + # Escape content for sed using files for safety |
| 122 | + sed -E "s/[\/&]/\\&/g" issue_content.txt > escaped_content.txt |
| 123 | + ESCAPED_CONTENT=$(cat escaped_content.txt) |
| 124 | +
|
| 125 | + # Look for the section and apply the change |
| 126 | + # This is a basic approach; more sophisticated section matching might be needed |
| 127 | + if grep -q "$SECTION" "$FILE"; then |
| 128 | + # Try to find the section and replace content from the section title until the next section |
| 129 | + sed -i "/# $SECTION/,/# /c\\# $SECTION\n\n$ESCAPED_CONTENT\n\n# " "$FILE" |
| 130 | + else |
| 131 | + echo "Section not found: $SECTION in $FILE. Adding to the end of the file." |
| 132 | + echo -e "\n# $SECTION\n\n$CONTENT" >> "$FILE" |
| 133 | + fi |
| 134 | + done |
| 135 | +
|
| 136 | + # Clean up temporary files used in the loop |
| 137 | + rm -f issue_file.txt issue_section.txt issue_desc.txt issue_content.txt escaped_content.txt |
| 138 | + # Clean up json_output.txt after it's fully processed |
| 139 | + rm -f json_output.txt |
| 140 | +
|
| 141 | + # Set up git identity for Claude |
| 142 | + git config --local user.email "[email protected]" |
| 143 | + git config --local user.name "Claude" |
| 144 | +
|
| 145 | + # Commit the changes |
| 146 | + git add README.md ARCHITECTURE.md DEVELOPMENT.md |
| 147 | + git commit -m "docs: update documentation based on code analysis" |
| 148 | + git push origin "$BRANCH_NAME" |
| 149 | +
|
| 150 | + echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 151 | +
|
| 152 | + # Create summary of changes to display in PR |
| 153 | + CHANGES_SUMMARY="" |
| 154 | + for i in $(seq 0 $((ISSUES_FOUND - 1))); do |
| 155 | + FILE=$(echo "$JSON_OUTPUT" | jq -r ".issues_found[$i].file") |
| 156 | + SECTION=$(echo "$JSON_OUTPUT" | jq -r ".issues_found[$i].section") |
| 157 | + ISSUE=$(echo "$JSON_OUTPUT" | jq -r ".issues_found[$i].issue") |
| 158 | +
|
| 159 | + CHANGES_SUMMARY="${CHANGES_SUMMARY}- **${FILE}** (${SECTION}): ${ISSUE}\n" |
| 160 | + done |
| 161 | +
|
| 162 | + { |
| 163 | + echo "changes_summary<<EOF" |
| 164 | + echo -e "$CHANGES_SUMMARY" |
| 165 | + echo "EOF" |
| 166 | + } >> "$GITHUB_OUTPUT" |
| 167 | +
|
| 168 | + - name: Create Pull Request |
| 169 | + if: steps.process-updates.outputs.issues_found > 0 |
| 170 | + uses: anthropics/claude-pr-action@8b9d5bb25a638c9aa5103496c0139d99b4936d42 # v1 |
| 171 | + with: |
| 172 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 173 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 174 | + branch: ${{ steps.process-updates.outputs.branch_name }} |
| 175 | + base: main |
| 176 | + title: "docs: Update documentation to match current codebase" |
| 177 | + body: | |
| 178 | + This PR was automatically generated by Claude Code to update documentation files based on code analysis. |
| 179 | +
|
| 180 | + ## What's Changed |
| 181 | +
|
| 182 | + Documentation has been updated to match the current codebase. The following issues were addressed: |
| 183 | +
|
| 184 | + ${{ steps.process-updates.outputs.changes_summary }} |
| 185 | +
|
| 186 | + The following files were updated: |
| 187 | + - README.md |
| 188 | + - ARCHITECTURE.md |
| 189 | + - DEVELOPMENT.md |
| 190 | +
|
| 191 | + Please review these changes to ensure they accurately reflect the current state of the project. |
0 commit comments