-
-
Notifications
You must be signed in to change notification settings - Fork 864
119 lines (107 loc) 路 5.54 KB
/
Copy pathclaude-code-review.yml
File metadata and controls
119 lines (107 loc) 路 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Claude Code Review
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: true
type: string
jobs:
claude-review:
if: contains(fromJSON('["potatoqualitee","niphlod","andreasjordan"]'), github.actor)
runs-on: ubuntu-latest
env:
CLAUDE_CODE_SUBPROCESS_ENV_SCRUB: 1
permissions:
contents: read
pull-requests: read
issues: read
id-token: write # Required for the action to fetch a GitHub OIDC token
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: Validate PR number
shell: bash
env:
PR_NUMBER: ${{ github.event.inputs.pr_number }}
run: |
if [[ ! "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "PR number must be numeric"
exit 1
fi
- name: Set up bubblewrap for subprocess isolation
shell: bash
run: |
# CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 forces the Claude Code CLI to run every
# subprocess under bubblewrap with secrets (OAuth token, GITHUB_TOKEN, cloud
# creds) scrubbed from its environment. The CLI refuses to start if bubblewrap
# is missing, so install it on the runner before invoking the action.
# socat is the second half of the pair: it relays sandboxed network traffic
# through the sandbox proxy. Without it every Bash command that touches the
# network (gh, git push) dies on sandbox init. Neither package ships in the
# ubuntu-latest image. Ref: https://code.claude.com/docs/en/sandboxing
sudo apt-get update
sudo apt-get install -y bubblewrap socat
# Ubuntu 24.04 (ubuntu-latest) blocks unprivileged user namespaces via AppArmor,
# which bubblewrap needs. Rather than globally disabling the kernel restriction
# (kernel.apparmor_restrict_unprivileged_userns), load a dedicated AppArmor profile
# granting only /usr/bin/bwrap the userns capability - the same profile shape
# Ubuntu ships for Flatpak and Chrome - so host hardening stays intact.
# Ref: https://code.claude.com/docs/en/sandboxing
if [ "$(sysctl -n kernel.apparmor_restrict_unprivileged_userns 2>/dev/null || echo 0)" = "1" ]; then
sudo tee /etc/apparmor.d/bwrap > /dev/null <<'PROFILE'
abi <abi/4.0>,
include <tunables/global>
profile bwrap /usr/bin/bwrap flags=(unconfined) {
userns,
include if exists <local/bwrap>
}
PROFILE
sudo apparmor_parser -r /etc/apparmor.d/bwrap
fi
# Fail fast here if bwrap still cannot create a user namespace, instead of
# letting the Claude Code install fail later with a less obvious error.
bwrap --ro-bind / / --unshare-user true
echo "bubblewrap ready: $(bwrap --version)"
# The sandbox keeps commands from editing config dotfiles by bind-mounting
# over each one, and bwrap has to CREATE the mount point when the file does
# not exist. One set of those paths resolves under /home, which is root-owned
# on the runner, so the create fails and the sandbox aborts before bash ever
# starts. Every Bash tool call in the session then dies with
# bwrap: Can't create file at /home/.mcp.json: Permission denied
# which reads like a permissions denial on the command but is really sandbox
# bootstrap failing. Pre-create the paths so bwrap binds over something that
# already exists. Ref: https://github.com/anthropics/claude-code/issues/17258
for name in .gitconfig .gitmodules .bashrc .bash_profile .zshrc .zprofile .profile .ripgreprc; do
[ -e "/home/$name" ] || sudo install -m 644 /dev/null "/home/$name"
done
# Valid-but-empty JSON rather than a zero-byte file, in case anything on the
# runner parses this one as an MCP config instead of just mounting over it.
[ -e /home/.mcp.json ] || printf '{"mcpServers":{}}\n' | sudo tee /home/.mcp.json > /dev/null
for name in .vscode .idea .claude/commands .claude/agents; do
[ -d "/home/$name" ] || sudo install -d -m 755 "/home/$name"
done
echo "sandbox mount points ready in /home"
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@56cf60fde42f7b19c3abfd5c9c48b69a1288461f # v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.inputs.pr_number }}
Please review this pull request and provide feedback on:
- Code quality and best practices
- Potential bugs or issues
- Performance considerations
- Security concerns
- Test coverage
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
claude_args: >-
--max-turns 100
--allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"