Skip to content

Commit c5a58f7

Browse files
committed
feat(ci,docs): add GitHub workflows and enhance terminal integration
Change-Id: I07f93b765223c1fff958db89e9d89cc27c6a9c4c Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 723ccd9 commit c5a58f7

File tree

4 files changed

+448
-28
lines changed

4 files changed

+448
-28
lines changed

.github/workflows/docs-review.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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.
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
name: Update Changelog
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
update-changelog:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
17+
with:
18+
fetch-depth: 2 # We need at least 2 commits to get the last one
19+
persist-credentials: true
20+
21+
- name: Get commit message
22+
id: get-commit-msg
23+
shell: bash
24+
# zizmor-disable-next-line template-injection
25+
run: |
26+
COMMIT_MSG=$(git log -1 --pretty=%B)
27+
{
28+
echo "commit_msg=${COMMIT_MSG}"
29+
echo "commit_type=$(echo "${COMMIT_MSG}" | grep -o '^feat\|^fix\|^docs\|^style\|^refactor\|^perf\|^test\|^build\|^ci\|^chore' || echo 'other')"
30+
echo "commit_scope=$(echo "${COMMIT_MSG}" | grep -o '([^)]*)')"
31+
echo "commit_desc=$(echo "${COMMIT_MSG}" | sed -E 's/^(feat|fix|docs|style|refactor|perf|test|build|ci|chore)(\([^)]*\))?:\s*//')"
32+
} >> "$GITHUB_OUTPUT"
33+
34+
- name: Update Changelog
35+
id: update-changelog
36+
shell: bash
37+
# zizmor-disable-next-line template-injection
38+
env:
39+
COMMIT_TYPE_ENV: ${{ steps.get-commit-msg.outputs.commit_type }}
40+
COMMIT_SCOPE_ENV: ${{ steps.get-commit-msg.outputs.commit_scope }}
41+
COMMIT_DESC_ENV: ${{ steps.get-commit-msg.outputs.commit_desc }}
42+
run: |
43+
# Assign environment variables directly to shell variables
44+
COMMIT_TYPE="$COMMIT_TYPE_ENV"
45+
COMMIT_SCOPE="$COMMIT_SCOPE_ENV"
46+
COMMIT_DESC="$COMMIT_DESC_ENV"
47+
48+
# Clean up scope format for display
49+
SCOPE=""
50+
if [ -n "$COMMIT_SCOPE" ]; then
51+
SCOPE=$(echo "$COMMIT_SCOPE" | sed -E 's/^\(([^)]*)\)$/\1/')
52+
SCOPE=" ($SCOPE)"
53+
fi
54+
55+
# Format changelog entry based on commit type
56+
ENTRY="- $COMMIT_DESC$SCOPE"
57+
58+
# Determine which section to add the entry to
59+
SECTION=""
60+
case "$COMMIT_TYPE" in
61+
feat)
62+
SECTION="Added"
63+
;;
64+
fix)
65+
SECTION="Fixed"
66+
;;
67+
docs)
68+
SECTION="Documentation"
69+
;;
70+
style|refactor)
71+
SECTION="Changed"
72+
;;
73+
perf)
74+
SECTION="Performance"
75+
;;
76+
test|build|ci|chore)
77+
# Skip these commit types for changelog
78+
echo "Skipping changelog update for commit type: $COMMIT_TYPE"
79+
exit 0
80+
;;
81+
*)
82+
# For other commit types, put in Changed section
83+
SECTION="Changed"
84+
;;
85+
esac
86+
87+
# Prepare a new branch
88+
BRANCH_NAME="changelog/update-$COMMIT_TYPE-$(date +%Y%m%d%H%M%S)"
89+
git checkout -b "$BRANCH_NAME"
90+
91+
# Check if the section exists, if not, create it
92+
if ! grep -q "### $SECTION" CHANGELOG.md; then
93+
# Add the section after "## [Unreleased]" line
94+
sed -i "/## \[Unreleased\]/a \\\n### $SECTION\n" CHANGELOG.md
95+
fi
96+
97+
# Add entry to the section
98+
# Ensure ENTRY is quoted to handle potential special characters if it were used in a more complex sed command,
99+
# but for 'a' (append), it's generally safer.
100+
sed -i "/### $SECTION/a $ENTRY" CHANGELOG.md
101+
102+
# Check if any changes were made
103+
if git diff --quiet CHANGELOG.md; then
104+
echo "No changes made to CHANGELOG.md"
105+
# No temp files to clean up here for commit details if exiting early
106+
exit 0
107+
fi
108+
109+
# Write outputs directly to GITHUB_OUTPUT using a block redirect
110+
{
111+
echo "changelog_updated=true"
112+
echo "branch_name=$BRANCH_NAME"
113+
echo "commit_type=$COMMIT_TYPE"
114+
echo "commit_desc=$COMMIT_DESC"
115+
echo "section=$SECTION"
116+
} >> "$GITHUB_OUTPUT"
117+
118+
# No temp files like commit_type.txt, etc. were created in this block anymore
119+
120+
- name: Set up git identity for Claude
121+
if: steps.update-changelog.outputs.changelog_updated == 'true'
122+
shell: bash
123+
# zizmor-disable-next-line template-injection
124+
run: |
125+
git config --local user.email "[email protected]"
126+
git config --local user.name "Claude"
127+
128+
- name: Commit changes
129+
if: steps.update-changelog.outputs.changelog_updated == 'true'
130+
shell: bash
131+
# zizmor-disable-next-line template-injection
132+
env:
133+
COMMIT_TYPE_ENV: ${{ steps.get-commit-msg.outputs.commit_type }}
134+
COMMIT_SCOPE_ENV: ${{ steps.get-commit-msg.outputs.commit_scope }}
135+
BRANCH_NAME_ENV: ${{ steps.update-changelog.outputs.branch_name }}
136+
run: |
137+
# Assign environment variables directly to shell variables
138+
COMMIT_TYPE="$COMMIT_TYPE_ENV"
139+
COMMIT_SCOPE="$COMMIT_SCOPE_ENV"
140+
BRANCH_NAME="$BRANCH_NAME_ENV"
141+
142+
git add CHANGELOG.md
143+
git commit -m "docs(changelog): update for ${COMMIT_TYPE}${COMMIT_SCOPE}"
144+
git push --set-upstream origin "$BRANCH_NAME"
145+
146+
# No temp files to clean up here
147+
148+
- name: Create Pull Request
149+
if: steps.update-changelog.outputs.changelog_updated == 'true'
150+
uses: actions/github-script@v7
151+
with:
152+
github-token: ${{ secrets.GITHUB_TOKEN }}
153+
script: |
154+
const commitType = process.env.COMMIT_TYPE;
155+
const commitDesc = process.env.COMMIT_DESC;
156+
const section = process.env.SECTION;
157+
const branchName = process.env.BRANCH_NAME;
158+
159+
try {
160+
const pr = await github.rest.pulls.create({
161+
owner: context.repo.owner,
162+
repo: context.repo.repo,
163+
title: `docs(changelog): Update ${section} section for ${commitType} changes`,
164+
head: branchName,
165+
base: 'main',
166+
body: `This PR was automatically generated to update the CHANGELOG.md file.
167+
168+
## Changes
169+
170+
Added to the **${section}** section:
171+
\`\`\`
172+
- ${commitDesc}
173+
\`\`\`
174+
175+
This change reflects the latest commit to the main branch.
176+
177+
---
178+
179+
🤖 Generated with [Claude Code](https://claude.ai/code)`
180+
});
181+
182+
console.log(`Pull Request created: ${pr.data.html_url}`);
183+
184+
} catch (error) {
185+
console.error('Error creating pull request:', error);
186+
core.setFailed('Failed to create pull request');
187+
}
188+
env:
189+
COMMIT_TYPE: ${{ steps.update-changelog.outputs.commit_type }}
190+
COMMIT_DESC: ${{ steps.update-changelog.outputs.commit_desc }}
191+
SECTION: ${{ steps.update-changelog.outputs.section }}
192+
BRANCH_NAME: ${{ steps.update-changelog.outputs.branch_name }}

0 commit comments

Comments
 (0)