Skip to content

Commit e9aa599

Browse files
authored
ci: add AI code review workflow (Claude on Bedrock) (#6053)
Adds an automated PR review using anthropics/claude-code-action@v1 running on Amazon Bedrock. Inference stays in-account and is CloudTrail-audited; no external API key is required. Reuses the existing collaborator gate from pr-checks-master.yml so that collaborator PRs auto-run and fork/external PRs require manual approval before any secret or the Bedrock role is exposed (safe under pull_request_target).
1 parent b8b4518 commit e9aa599

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: AI Code Review (Claude on Bedrock)
2+
3+
# Automated PR review using Anthropic's Claude Code Action running on Amazon
4+
# Bedrock (inference stays in-account, CloudTrail-audited, no external API key).
5+
#
6+
# Fork safety: this uses pull_request_target (needed to access the Bedrock role
7+
# and post comments), so it reuses the same collaborator gate as
8+
# pr-checks-master.yml. Collaborator PRs -> `auto-approve` env (runs immediately).
9+
# Fork/external PRs -> `manual-approval` env (a maintainer must approve the run
10+
# before any secret or the Bedrock role is exposed).
11+
12+
on:
13+
pull_request_target:
14+
types: [opened, synchronize, ready_for_review, reopened]
15+
branches:
16+
- "master"
17+
# Scope to the same product directories the other PR checks use, so pure
18+
# docs/example PRs don't trigger a model review. Remove this block to
19+
# review every PR.
20+
paths:
21+
- 'sagemaker-train/**'
22+
- 'sagemaker-serve/**'
23+
- 'sagemaker-mlops/**'
24+
- 'sagemaker-core/**'
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref }}
28+
cancel-in-progress: true
29+
30+
permissions:
31+
id-token: write # OIDC federation to assume the Bedrock role
32+
pull-requests: write # post inline review comments and a summary
33+
contents: read
34+
35+
jobs:
36+
# Identical gate to pr-checks-master.yml: collaborators auto-approve,
37+
# everyone else requires manual approval via the `manual-approval` environment.
38+
collab-check:
39+
runs-on: ubuntu-latest
40+
outputs:
41+
approval-env: ${{ steps.collab-check.outputs.result }}
42+
steps:
43+
- name: Collaborator Check
44+
uses: actions/github-script@v7
45+
id: collab-check
46+
with:
47+
github-token: ${{ secrets.COLLAB_CHECK_TOKEN }}
48+
result-encoding: string
49+
script: |
50+
try {
51+
const res = await github.rest.repos.checkCollaborator({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
username: "${{ github.event.pull_request.user.login }}",
55+
});
56+
console.log("Verified ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto approving AI review.")
57+
return res.status == "204" ? "auto-approve" : "manual-approval"
58+
} catch (error) {
59+
console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring manual approval to run AI review.")
60+
return "manual-approval"
61+
}
62+
63+
wait-for-approval:
64+
runs-on: ubuntu-latest
65+
needs: [collab-check]
66+
environment: ${{ needs.collab-check.outputs.approval-env }}
67+
steps:
68+
- run: echo "Approved — starting AI code review."
69+
70+
review:
71+
runs-on: ubuntu-latest
72+
needs: [wait-for-approval]
73+
steps:
74+
- uses: actions/checkout@v4
75+
with:
76+
ref: ${{ github.event.pull_request.head.sha }}
77+
fetch-depth: 1
78+
79+
- name: Configure AWS Credentials
80+
uses: aws-actions/configure-aws-credentials@v4
81+
with:
82+
role-to-assume: ${{ secrets.CODE_REVIEW_ROLE }}
83+
aws-region: us-west-2
84+
85+
- uses: anthropics/claude-code-action@v1
86+
with:
87+
github_token: ${{ secrets.GITHUB_TOKEN }}
88+
use_bedrock: "true"
89+
track_progress: true
90+
claude_args: |
91+
--model us.anthropic.claude-opus-4-8
92+
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
93+
prompt: |
94+
REPO: ${{ github.repository }}
95+
PR NUMBER: ${{ github.event.pull_request.number }}
96+
97+
Review this pull request for the SageMaker Python SDK. Focus on:
98+
- Correctness: bugs, incorrect API/argument usage, breaking changes
99+
to public interfaces, backward-incompatibility for SDK consumers
100+
- Python best practices and readability
101+
- Security implications (credential handling, input validation)
102+
- Performance considerations
103+
- Missing or inadequate tests for changed behavior
104+
105+
Post specific issues as inline comments. Skip nits and style the
106+
linters already enforce. If the PR looks clean, say so briefly.

0 commit comments

Comments
 (0)