Skip to content

Commit c8dc7d4

Browse files
authored
Add Claude Code GitHub Workflow (#1760)
## 🤖 Installing Claude Code GitHub App This PR adds a GitHub Actions workflow that enables Claude Code integration in our repository. ### What is Claude Code? [Claude Code](https://claude.ai/code) is an AI coding agent that can help with: - Bug fixes and improvements - Documentation updates - Implementing new features - Code reviews and suggestions - Writing tests - And more! ### How it works Once this PR is merged, we'll be able to interact with Claude by mentioning @claude in a pull request or issue comment. Once the workflow is triggered, Claude will analyze the comment and surrounding context, and execute on the request in a GitHub action. ### Important Notes - **This workflow won't take effect until this PR is merged** - **@claude mentions won't work until after the merge is complete** - The workflow runs automatically whenever Claude is mentioned in PR or issue comments - Claude gets access to the entire PR or issue context including files, diffs, and previous comments ### Security - Our Anthropic API key is securely stored as a GitHub Actions secret - Only users with write access to the repository can trigger the workflow - All Claude runs are stored in the GitHub Actions run history - Claude's default tools are limited to reading/writing files and interacting with our repo by creating comments, branches, and commits. - We can add more allowed tools by adding them to the workflow file like: ``` allowed_tools: Bash(npm install),Bash(npm run build),Bash(npm run lint),Bash(npm run test) ``` There's more information in the [Claude Code documentation](http://docs.anthropic.com/s/claude-code-github-actions). After merging this PR, let's try mentioning @claude in a comment on any PR to get started!
1 parent aafc796 commit c8dc7d4

File tree

3 files changed

+233
-0
lines changed

3 files changed

+233
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Claude Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
claude-review:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: read
13+
issues: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
22+
- name: Run Claude Code Review
23+
id: claude-review
24+
uses: anthropics/claude-code-action@beta
25+
with:
26+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
27+
28+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
29+
# model: "claude-opus-4-20250514"
30+
31+
# Direct prompt for automated review (no @claude mention needed)
32+
direct_prompt: |
33+
Please review this pull request and provide feedback on:
34+
- Code quality and best practices
35+
- Potential bugs or issues
36+
- Performance considerations
37+
- Security concerns
38+
- Test coverage
39+
40+
Be constructive and helpful in your feedback.
41+
42+
# Optional: Customize review based on file types
43+
# direct_prompt: |
44+
# Review this PR focusing on:
45+
# - For TypeScript files: Type safety and proper interface usage
46+
# - For API endpoints: Security, input validation, and error handling
47+
# - For React components: Performance, accessibility, and best practices
48+
# - For tests: Coverage, edge cases, and test quality
49+
50+
# Optional: Different prompts for different authors
51+
# direct_prompt: |
52+
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
53+
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
54+
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
55+
56+
# Optional: Add specific tools for running tests or linting
57+
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
58+
59+
# Optional: Skip review for certain conditions
60+
# if: |
61+
# !contains(github.event.pull_request.title, '[skip-review]') &&
62+
# !contains(github.event.pull_request.title, '[WIP]')

.github/workflows/claude.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pull-requests: read
24+
issues: read
25+
id-token: write
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 1
31+
32+
- name: Run Claude Code
33+
id: claude
34+
uses: anthropics/claude-code-action@beta
35+
with:
36+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
37+
38+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
39+
# model: "claude-opus-4-20250514"
40+
41+
# Optional: Customize the trigger phrase (default: @claude)
42+
# trigger_phrase: "/claude"
43+
44+
# Optional: Trigger when specific user is assigned to an issue
45+
# assignee_trigger: "claude-bot"
46+
47+
# Optional: Allow Claude to run specific commands
48+
# allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
49+
50+
# Optional: Add custom instructions for Claude to customize its behavior for your project
51+
# custom_instructions: |
52+
# Follow our coding standards
53+
# Ensure all new code has tests
54+
# Use TypeScript for new files
55+
56+
# Optional: Custom environment variables for Claude
57+
# claude_env: |
58+
# NODE_ENV: test
59+

.github/workflows/docs-sync.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Documentation Sync
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
8+
jobs:
9+
docs-sync:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
id-token: write
16+
17+
steps:
18+
- name: Checkout controller repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Get changed files
24+
id: changed-files
25+
run: |
26+
# Get list of changed files in the merged PR
27+
git fetch origin main
28+
CHANGED_FILES=$(git diff --name-only origin/main~1 origin/main)
29+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
30+
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
31+
echo "EOF" >> $GITHUB_OUTPUT
32+
33+
- name: Check if docs update needed
34+
id: check-docs
35+
run: |
36+
# Check if changes require documentation updates
37+
NEEDS_DOCS_UPDATE=false
38+
39+
# Define patterns that typically require docs updates
40+
DOCS_PATTERNS=(
41+
"^src/.*\.ts$"
42+
"^src/.*\.tsx$"
43+
"^packages/.*/src/.*\.ts$"
44+
"^packages/.*/src/.*\.tsx$"
45+
"^README\.md$"
46+
"^CHANGELOG\.md$"
47+
"^docs/"
48+
"package\.json$"
49+
"^api/"
50+
"^schema/"
51+
)
52+
53+
while IFS= read -r file; do
54+
for pattern in "${DOCS_PATTERNS[@]}"; do
55+
if [[ $file =~ $pattern ]]; then
56+
NEEDS_DOCS_UPDATE=true
57+
break 2
58+
fi
59+
done
60+
done <<< "${{ steps.changed-files.outputs.changed_files }}"
61+
62+
echo "needs_update=$NEEDS_DOCS_UPDATE" >> $GITHUB_OUTPUT
63+
echo "Files that may need docs updates: ${{ steps.changed-files.outputs.changed_files }}"
64+
65+
- name: Checkout docs repository
66+
if: steps.check-docs.outputs.needs_update == 'true'
67+
uses: actions/checkout@v4
68+
with:
69+
repository: cartridge-gg/docs
70+
token: ${{ secrets.CREATE_PR_TOKEN }}
71+
path: docs-repo
72+
73+
- name: Analyze changes and create docs PR
74+
if: steps.check-docs.outputs.needs_update == 'true'
75+
uses: anthropics/claude-code-action@beta
76+
with:
77+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
78+
direct_prompt: |
79+
I need you to analyze the changes in this controller repository PR and determine if the documentation in the cartridge-gg/docs repository needs to be updated.
80+
81+
**PR Information:**
82+
- Title: ${{ github.event.pull_request.title }}
83+
- Description: ${{ github.event.pull_request.body }}
84+
- Files changed: ${{ steps.changed-files.outputs.changed_files }}
85+
86+
**Your tasks:**
87+
1. Review the changed files and PR description to understand what functionality was added, modified, or removed
88+
2. Check the docs-repo directory to see what documentation currently exists
89+
3. Determine if any existing documentation needs updates or if new documentation should be created
90+
4. If updates are needed:
91+
- Create or update the appropriate documentation files
92+
- Ensure the documentation accurately reflects the current state of the controller
93+
- Follow the existing documentation style and structure
94+
- Create a new branch in the docs repo
95+
- Commit the changes with a descriptive message
96+
- Create a pull request in the docs repository
97+
98+
**Important guidelines:**
99+
- Only create documentation updates if they are actually needed
100+
- Focus on user-facing changes, API changes, new features, or breaking changes
101+
- Don't document internal implementation details unless they affect usage
102+
- If no documentation updates are needed, simply state that and exit
103+
104+
The docs repository is checked out in the `docs-repo` directory. Please analyze the controller changes and update the documentation accordingly.
105+
106+
allowed_tools: "Bash(git *),Bash(cd *),Read,Write,Edit,MultiEdit,Glob,Grep"
107+
108+
- name: Cleanup
109+
if: always()
110+
run: |
111+
# Clean up any temporary files or directories
112+
rm -rf docs-repo || true

0 commit comments

Comments
 (0)