Skip to content

Commit 6258319

Browse files
cgrindelclaude
andauthored
chore: add Claude Code GitHub Workflow (#1707)
## 🤖 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 the repository owner (cgrindel) can trigger the Claude workflow** - Draft PRs are automatically skipped for code reviews - 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(bazel test //...),Bash(bazel run //:tidy),Bash(bazel run //:update_build_files)" ``` 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\! --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3be8d2e commit 6258319

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Claude Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
# Optional: Only run on specific file changes
7+
# paths:
8+
# - "src/**/*.ts"
9+
# - "src/**/*.tsx"
10+
# - "src/**/*.js"
11+
# - "src/**/*.jsx"
12+
13+
jobs:
14+
claude-review:
15+
# Skip draft PRs
16+
if: github.event.pull_request.draft == false
17+
18+
# Optional: Filter by PR author
19+
# if: |
20+
# github.event.pull_request.user.login == 'external-contributor' ||
21+
# github.event.pull_request.user.login == 'new-developer' ||
22+
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
23+
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
pull-requests: read
28+
issues: read
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 1
36+
37+
- name: Run Claude Code Review
38+
id: claude-review
39+
uses: anthropics/claude-code-action@beta
40+
with:
41+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
42+
43+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
44+
# model: "claude-opus-4-20250514"
45+
46+
# Direct prompt for automated review (no @claude mention needed)
47+
direct_prompt: |
48+
Please review this pull request for a Bazel-based Swift package manager ruleset and provide feedback on:
49+
- Bazel rule implementation and best practices
50+
- Swift package handling correctness
51+
- Build file generation logic
52+
- Performance considerations for large dependency graphs
53+
- Security concerns in package resolution
54+
- Test coverage for new Bazel rules and Swift functionality
55+
- Documentation updates for new features
56+
57+
Focus on Bazel-specific patterns, Swift package compatibility, and the interaction between Bazel rules and Swift Package Manager.
58+
Be constructive and helpful in your feedback.
59+
60+
# Optional: Customize review based on file types
61+
# direct_prompt: |
62+
# Review this PR focusing on:
63+
# - For TypeScript files: Type safety and proper interface usage
64+
# - For API endpoints: Security, input validation, and error handling
65+
# - For React components: Performance, accessibility, and best practices
66+
# - For tests: Coverage, edge cases, and test quality
67+
68+
# Optional: Different prompts for different authors
69+
# direct_prompt: |
70+
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
71+
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
72+
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
73+
74+
# Optional: Add specific tools for running tests or linting
75+
allowed_tools: "Bash(bazel test //...),Bash(bazel build //...),Bash(bazel run //:tidy)"
76+
77+
# Optional: Skip review for certain conditions
78+
# if: |
79+
# !contains(github.event.pull_request.title, '[skip-review]') &&
80+
# !contains(github.event.pull_request.title, '[WIP]')
81+

.github/workflows/claude.yml

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

CLAUDE.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this
4+
repository.
5+
6+
## Overview
7+
8+
This is `rules_swift_package_manager` - a Bazel ruleset for downloading, building, and consuming
9+
Swift packages. It builds external Swift packages using rules_swift, rules_apple, and native C/C++
10+
rulesets, making Swift package products and targets available as Bazel targets.
11+
12+
## Common Development Commands
13+
14+
### Building and Testing
15+
16+
- `bazel test //...` - Run all tests in the repository
17+
- `bazel build //...` - Build all targets
18+
19+
### Code Maintenance
20+
21+
- `bazel run //:tidy` - Update source files from build outputs
22+
- `bazel run //:update_build_files` - Update Bazel BUILD files using Gazelle
23+
- `bazel run //:update_files` - Quick update of source files
24+
- `bazel run //:tidy_all` - Run all tidy operations across the repository
25+
26+
### Go-specific Commands
27+
28+
- `bazel run //:go_mod_tidy` - Tidy Go module dependencies
29+
- `bazel run //:go_get_latest` - Update Go dependencies to latest versions
30+
31+
### Example Testing
32+
33+
Examples have individual `do_test` scripts that can be run to test specific functionality.
34+
35+
## Architecture
36+
37+
### Core Components
38+
39+
1. **swiftpkg/** - Main Swift package management logic
40+
41+
- `defs.bzl` - Public API exports
42+
- `internal/` - Core implementation including:
43+
- Swift package repository rules (`swift_package.bzl`, `local_swift_package.bzl`)
44+
- Build file generation (`build_files.bzl`, `swiftpkg_build_files.bzl`)
45+
- Package info processing (`pkginfos.bzl`, `pkginfo_*.bzl`)
46+
- Resource handling (`resource_files.bzl`, `resource_bundle_accessor.bzl`)
47+
- `bzlmod/` - Bazel module extension for Swift dependencies
48+
49+
2. **tools/swift_deps_index/** - Go-based tooling for Swift dependency analysis
50+
51+
- Processes Swift package manifests and resolution data
52+
- Generates dependency indexes and metadata
53+
54+
3. **examples/** - Comprehensive test examples for different Swift package scenarios
55+
56+
- Each example has its own `do_test` script and demonstrates specific features
57+
58+
4. **ci/** - Continuous integration configuration and test definitions
59+
60+
### Key Files
61+
62+
- `extensions.bzl` - Bazel module extensions entry point
63+
- `MODULE.bazel` - Bazel module configuration with runtime dependencies
64+
- `shared.bazelrc` - Common Bazel configuration (bzlmod enabled, Apple toolchain setup)
65+
- `BUILD.bazel` - Root build configuration with Gazelle and maintenance targets
66+
67+
### Testing Strategy
68+
69+
The repository uses extensive integration testing with examples covering real-world Swift package
70+
scenarios like Firebase, gRPC, Stripe, and others. Tests verify both bzlmod and workspace modes.
71+
72+
## Important Notes
73+
74+
- This repository uses bzlmod by default (`--enable_bzlmod` in shared.bazelrc)
75+
- Apple toolchain configuration is handled automatically via apple_support
76+
- Swift package resolution requires `Package.swift` and `Package.resolved` files
77+
- The `tidy` target is crucial for maintaining generated BUILD files and dependencies
78+
79+
## Development Best Practices
80+
81+
- Always use conventional commit format for git commit messages

0 commit comments

Comments
 (0)