Skip to content

Commit 9a1fe43

Browse files
authored
Merge pull request #484 from authzed/add-claude-github-actions-1768426712733
Add Claude Code GitHub Workflow and Suggestion workflow
2 parents 5198ac3 + 0a4b2f8 commit 9a1fe43

7 files changed

Lines changed: 343 additions & 144 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Claude Code Review"
2+
3+
"on":
4+
pull_request:
5+
types:
6+
[
7+
"opened",
8+
"synchronize",
9+
"ready_for_review",
10+
"reopened",
11+
"labeled",
12+
"edited",
13+
]
14+
# Optional: Only run on specific file changes
15+
# paths:
16+
# - "src/**/*.ts"
17+
# - "src/**/*.tsx"
18+
# - "src/**/*.js"
19+
# - "src/**/*.jsx"
20+
21+
jobs:
22+
claude-review:
23+
# Only run when:
24+
# - The 'claude-review' label is present, OR
25+
# - The PR description contains '@claude'
26+
if: |
27+
contains(github.event.pull_request.labels.*.name, 'claude-review') ||
28+
contains(github.event.pull_request.body, '@claude')
29+
30+
runs-on: "ubuntu-latest"
31+
permissions:
32+
contents: "read"
33+
pull-requests: "read"
34+
issues: "read"
35+
id-token: "write"
36+
37+
steps:
38+
- name: "Checkout repository"
39+
uses: "actions/checkout@v4"
40+
with:
41+
fetch-depth: 1
42+
43+
- name: "Run Claude Code Review"
44+
id: "claude-review"
45+
uses: "anthropics/claude-code-action@v1"
46+
with:
47+
anthropic_api_key: "${{ secrets.ANTHROPIC_API_KEY }}"
48+
plugin_marketplaces: "https://github.com/anthropics/claude-code.git"
49+
plugins: "code-review@claude-code-plugins"
50+
prompt: "/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
51+
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
52+
# or https://code.claude.com/docs/en/cli-reference for available options

.github/workflows/claude.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: "Claude Code"
2+
# Note: only users with write permissions can invoke Claude jobs
3+
4+
"on":
5+
issue_comment:
6+
types: ["created"]
7+
pull_request_review_comment:
8+
types: ["created"]
9+
issues:
10+
types: ["labeled"]
11+
pull_request_review:
12+
types: ["submitted"]
13+
workflow_dispatch:
14+
inputs:
15+
issue_number:
16+
description: "Issue number to process"
17+
required: true
18+
type: "number"
19+
20+
jobs:
21+
# Disable general claude invocations
22+
# claude:
23+
# if: |
24+
# (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
25+
# (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
26+
# (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
27+
# (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
28+
# runs-on: ubuntu-latest
29+
# permissions:
30+
# contents: read
31+
# pull-requests: read
32+
# issues: read
33+
# id-token: write
34+
# actions: read # Required for Claude to read CI results on PRs
35+
# steps:
36+
# - name: Checkout repository
37+
# uses: actions/checkout@v4
38+
# with:
39+
# fetch-depth: 1
40+
#
41+
# - name: Run Claude Code
42+
# id: claude
43+
# uses: anthropics/claude-code-action@v1
44+
# with:
45+
# anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
46+
#
47+
# # This is an optional setting that allows Claude to read CI results on PRs
48+
# additional_permissions: |
49+
# actions: read
50+
#
51+
# # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
52+
# # prompt: 'Update the pull request description to include a summary of changes.'
53+
#
54+
# # Optional: Add claude_args to customize behavior and configuration
55+
# # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
56+
# # or https://code.claude.com/docs/en/cli-reference for available options
57+
# # claude_args: '--allowed-tools Bash(gh pr:*)'
58+
59+
suggestion:
60+
name: "Suggestion Handler"
61+
if: |
62+
(github.event_name == 'issues' &&
63+
github.event.action == 'labeled' &&
64+
contains(github.event.issue.labels.*.name, 'suggestion/accepted')) ||
65+
github.event_name == 'workflow_dispatch'
66+
runs-on: "ubuntu-latest"
67+
permissions:
68+
contents: "write"
69+
pull-requests: "read"
70+
issues: "write"
71+
id-token: "write"
72+
steps:
73+
- name: "Checkout repository"
74+
uses: "actions/checkout@v4"
75+
with:
76+
fetch-depth: 0
77+
78+
- name: "Validate issue label for manual trigger"
79+
if: "github.event_name == 'workflow_dispatch'"
80+
env:
81+
GH_TOKEN: "${{ github.token }}"
82+
ISSUE_NUMBER: "${{ inputs.issue_number }}"
83+
run: |
84+
labels=$(gh issue view $ISSUE_NUMBER --json labels --jq '.labels[].name' || echo "")
85+
if ! echo "$labels" | grep -q "suggestion/accepted"; then
86+
echo "Error: Issue #$ISSUE_NUMBER does not have the 'suggestion/accepted' label"
87+
exit 1
88+
fi
89+
echo "Issue #$ISSUE_NUMBER has the required 'suggestion/accepted' label"
90+
91+
# Runs claude code implement the suggestion.
92+
# Configured to give 50 turns to claude based on observations. This can be increased if we observe sessions failing to complete
93+
- name: "Run Claude Code for Suggestion"
94+
id: "claude-suggestion"
95+
uses: "anthropics/claude-code-action@v1"
96+
env:
97+
ISSUE_NUMBER: "${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }}"
98+
with:
99+
anthropic_api_key: "${{ secrets.ANTHROPIC_API_KEY }}"
100+
# Enabling this may expose secrets. Do not set to true on public repos
101+
# https://github.com/anthropics/claude-code-action/blob/main/docs/security.md#%EF%B8%8F-full-output-security-warning
102+
show_full_output: false
103+
prompt: |
104+
Read the repository documentation structure and the issue description for issue #${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }}.
105+
106+
The issue has been labeled as "suggestion/accepted" and contains a documentation request or improvement.
107+
108+
Your task:
109+
1. Read and understand the current documentation structure in this repository
110+
2. Review the issue description and any comments to understand what documentation changes are needed
111+
3. Create a new branch using the format: suggestion/issue-${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }}-<short-description>
112+
Example: suggestion/issue-1-starter-program-docs
113+
Use: git checkout -b <branch-name>
114+
4. Implement the requested documentation changes by editing existing pages or creating new pages as appropriate
115+
5. Ensure all changes follow the existing documentation style, formatting, and structure
116+
6. Commit your changes with messages that include "Fixes #${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }}" so the issue will automatically close when the PR is merged.
117+
7. Push your branch to origin using: git push -u origin <branch-name>
118+
8. Post a comment to issue #${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }} with:
119+
- Summary of changes made
120+
- Link to create a PR using: https://github.com/${{ github.repository }}/compare/<branch-name>?expand=1
121+
Use the gh CLI: gh issue comment ${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }} --body "<your comment>"
122+
123+
Focus only on documentation changes. Make app changes necessary to support the documentation such as adding visual components, icons, and structure.
124+
Otherwise, do not modify application code, configuration files, or CI/CD workflows.
125+
claude_args: |
126+
--allowedTools "Read,Write,Edit,Bash(git:*),Bash(gh:*),WebFetch(domain:authzed.com)"
127+
--max-turns 50

CLAUDE.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# AuthZed Docs
2+
3+
Documentation site for AuthZed and SpiceDB built with Next.js and Nextra.
4+
5+
## Stack
6+
7+
- **Framework**: Next.js 16 (App Router)
8+
- **Documentation**: Nextra 4.6 (docs theme)
9+
- **Styling**: Tailwind CSS 4
10+
- **Package Manager**: pnpm 10.24.0
11+
- **TypeScript**: 5.9.3 (non-strict mode, strict null checks enabled)
12+
- **Content Format**: MDX (Markdown + JSX)
13+
14+
## Project Structure
15+
16+
```
17+
app/
18+
├── authzed/ # AuthZed product docs
19+
├── spicedb/ # SpiceDB docs
20+
├── best-practices/ # Best practices guides
21+
├── mcp/ # MCP-related docs
22+
├── page.mdx # Homepage
23+
├── layout.tsx # Root layout
24+
└── globals.css # Global styles
25+
26+
components/
27+
├── ui/ # Reusable UI components
28+
├── banner.tsx
29+
├── cta.tsx
30+
└── youtube-wrapper.tsx
31+
32+
scripts/ # Build and utility scripts
33+
```
34+
35+
## Content Conventions
36+
37+
### File Organization
38+
39+
- Each section has a `_meta.ts` file defining navigation order and titles
40+
- Content files are `page.mdx` within directories (e.g., `app/authzed/guides/cloud/page.mdx`)
41+
- Import path alias: `@/*` maps to root directory
42+
43+
### MDX Files
44+
45+
**Imports at top:**
46+
47+
```tsx
48+
import { Callout } from "nextra/components";
49+
import YouTube from "@/components/youtube-wrapper";
50+
```
51+
52+
**Common patterns:**
53+
54+
- Use `<Callout type="info|warning|error">` for callouts
55+
- Use `<YouTube videoId="..." className="youtubeContainer" />` for videos
56+
- Standard markdown for content (headings, lists, code blocks, links)
57+
58+
### Code Style
59+
60+
- **Path aliases**: Use `@/` for imports from root (e.g., `@/components/banner`)
61+
- **Components**: React functional components with TypeScript
62+
- **Formatting**: Prettier (run `pnpm format`)
63+
- **Linting**: Markdownlint with custom rules (run `pnpm lint:markdown`)
64+
65+
## Development
66+
67+
```bash
68+
pnpm dev # Start dev server
69+
pnpm build # Build for production
70+
pnpm format # Format code
71+
pnpm lint:markdown # Lint markdown files
72+
```
73+
74+
## Notes
75+
76+
- Markdown linting is lenient (most rules disabled, custom sentence-per-line rule)
77+
- TypeScript strict mode is off, but strict null checks are enforced
78+
- Next.js uses webpack mode explicitly (`--webpack` flag)

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,38 @@ Run linters:
4242
```sh
4343
pnpm run lint
4444
```
45+
46+
## Automated Documentation Suggestions
47+
48+
This repository uses GitHub Actions with Claude Code to automatically implement accepted documentation suggestions.
49+
50+
### How It Works
51+
52+
1. **Create an issue** describing the documentation change, addition, or improvement you'd like to see
53+
2. To approve a suggestion issue, **add the `suggestion/accepted` label** to the issue
54+
3. **Claude automatically**:
55+
- Reads the issue description and existing documentation
56+
- Creates a new branch (`claude/issue-N-description`)
57+
- Implements the requested documentation changes
58+
- Commits with "Fixes #N" to auto-close the issue when merged
59+
- Pushes the branch and comments on the issue with a PR link
60+
- A repo admin then clicks the PR link to create a PR, reviews it, and merges when ready
61+
62+
### Manual Trigger
63+
64+
You can also manually trigger the suggestion handler:
65+
66+
1. Go to the **Actions** tab
67+
2. Select **Claude Code** workflow
68+
3. Click **Run workflow**
69+
4. Enter the issue number
70+
5. The issue must have the `suggestion/accepted` label
71+
72+
### Review Process
73+
74+
After Claude creates the branch:
75+
76+
1. Create the PR using the link in the issue comment
77+
2. Review the changes in the generated PR link
78+
3. Make any changes and update the PR. Merge when satisfied
79+
4. The original issue will automatically close

0 commit comments

Comments
 (0)