-
Notifications
You must be signed in to change notification settings - Fork 8
333 lines (281 loc) · 12 KB
/
Copy pathcode-review.yml
File metadata and controls
333 lines (281 loc) · 12 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
pull_request_review_comment:
types: [created]
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
issues: write
id-token: write
jobs:
dep-update-check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
outputs:
dependency_only: ${{ steps.check.outputs.dependency_only }}
steps:
- uses: actions/github-script@v7
id: check
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.setOutput("dependency_only", "false");
return;
}
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
});
const patterns = [
/(^|\/)package\.json$/,
/(^|\/)bun\.lockb?$/,
/(^|\/)package-lock\.json$/,
/(^|\/)pnpm-lock\.yaml$/,
/(^|\/)yarn\.lock$/,
/(^|\/)Cargo\.toml$/,
/(^|\/)Cargo\.lock$/,
/(^|\/)go\.mod$/,
/(^|\/)go\.sum$/,
/(^|\/)requirements.*\.txt$/,
/(^|\/)pyproject\.toml$/,
/(^|\/)poetry\.lock$/,
/(^|\/)Pipfile(\.lock)?$/,
/(^|\/)Gemfile(\.lock)?$/,
/(^|\/)composer\.(json|lock)$/,
/(^|\/)(build|settings)\.gradle(\.kts)?$/,
/(^|\/)gradle\.lockfile$/,
/(^|\/)gradle\/libs\.versions\.toml$/,
];
const isDependencyFile = (filename) => patterns.some((re) => re.test(filename));
const dependencyOnly = files.length > 0 && files.every((file) => isDependencyFile(file.filename));
core.setOutput("dependency_only", dependencyOnly ? "true" : "false");
# Automatic review on new/updated PRs
claude-code-review:
# Only run for PRs from shepherdjerred on PR events (not comments)
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'shepherdjerred' &&
needs.dep-update-check.outputs.dependency_only != 'true'
needs: [dep-update-check]
runs-on: [monorepo-runner-set]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
- uses: 1password/load-secrets-action/configure@v2
with:
connect-host: http://onepassword-connect.1password.svc.cluster.local:8080
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
CLAUDE_CODE_OAUTH_TOKEN: op://bic45kuflnwsnxnd67dzcnxjze/5p65mbzr237yyzt2sfnfao3a5a/CLAUDE_CODE_OAUTH_TOKEN
- name: Extract kubectl version
id: kubectl-version
run: |
KUBECTL_VERSION=v1.34.1
echo "version=$KUBECTL_VERSION" >> "$GITHUB_OUTPUT"
- name: Cache kubectl
uses: actions/cache@v4
id: kubectl-cache
with:
path: ~/.local/bin/kubectl
key: kubectl-${{ steps.kubectl-version.outputs.version }}-linux-amd64
- name: Install kubectl
if: steps.kubectl-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/.local/bin
curl -LO "https://dl.k8s.io/release/${{ steps.kubectl-version.outputs.version }}/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl ~/.local/bin/
- name: Add kubectl to PATH
run: echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Extract Dagger version
id: dagger-version
run: |
DAGGER_IMAGE=$(kubectl get pod --selector=name=dagger-dagger-helm-engine --namespace=dagger -o jsonpath='{.items[0].spec.containers[0].image}')
DAGGER_VERSION="${DAGGER_IMAGE##*:v}"
echo "version=$DAGGER_VERSION" >> "$GITHUB_OUTPUT"
- name: Cache Dagger CLI
uses: actions/cache@v4
id: dagger-cache
with:
path: ~/.local/bin/dagger
key: dagger-${{ steps.dagger-version.outputs.version }}-linux-amd64
- name: Install Dagger CLI
if: steps.dagger-cache.outputs.cache-hit != 'true'
run: |
set -euo pipefail
DAGGER_VERSION="${{ steps.dagger-version.outputs.version }}"
BIN_DIR="$HOME/.local/bin"
# Try primary source first
if ! curl -fsSL https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION="$DAGGER_VERSION" BIN_DIR="$BIN_DIR" sh; then
echo "WARNING: Primary source (dl.dagger.io) failed, trying GitHub releases..."
# Fallback to GitHub releases
mkdir -p "$BIN_DIR"
DAGGER_URL="https://github.com/dagger/dagger/releases/download/v${DAGGER_VERSION}/dagger_v${DAGGER_VERSION}_linux_amd64.tar.gz"
echo "Downloading from: $DAGGER_URL"
curl -fsSL "$DAGGER_URL" | tar xz -C /tmp
mv /tmp/dagger "$BIN_DIR/dagger"
chmod +x "$BIN_DIR/dagger"
fi
# Verify installation
if [ ! -f "$BIN_DIR/dagger" ]; then
echo "ERROR: Dagger CLI installation failed"
exit 1
fi
"$BIN_DIR/dagger" version
- name: Get Dagger Engine Pod Name
run: |
DAGGER_ENGINE_POD_NAME="$(kubectl get pod --selector=name=dagger-dagger-helm-engine --namespace=dagger --output=jsonpath='{.items[0].metadata.name}')"
echo "_EXPERIMENTAL_DAGGER_RUNNER_HOST=kube-pod://$DAGGER_ENGINE_POD_NAME?namespace=dagger" >> "$GITHUB_ENV"
- name: Install Dagger module dependencies
working-directory: .dagger
run: bun install --frozen-lockfile
- name: Run Dagger code review
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
dagger call code-review \
--source=. \
--github-token=env:GH_TOKEN \
--claude-oauth-token=env:CLAUDE_CODE_OAUTH_TOKEN \
--pr-number="$PR_NUMBER" \
--base-branch="$BASE_BRANCH" \
--head-sha="$HEAD_SHA"
# Interactive responses to @claude mentions in comments
claude-interactive:
# Only run for comments from shepherdjerred that mention @claude
if: |
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
github.event.comment.user.login == 'shepherdjerred' &&
contains(github.event.comment.body, '@claude')
runs-on: [monorepo-runner-set]
# Cancel in-progress runs for the same PR to avoid duplicate responses
concurrency:
group: claude-interactive-${{ github.event.issue.number || github.event.pull_request.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
- uses: 1password/load-secrets-action/configure@v2
with:
connect-host: http://onepassword-connect.1password.svc.cluster.local:8080
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
CLAUDE_CODE_OAUTH_TOKEN: op://bic45kuflnwsnxnd67dzcnxjze/5p65mbzr237yyzt2sfnfao3a5a/CLAUDE_CODE_OAUTH_TOKEN
- name: Extract kubectl version
id: kubectl-version
run: |
KUBECTL_VERSION=v1.34.1
echo "version=$KUBECTL_VERSION" >> "$GITHUB_OUTPUT"
- name: Cache kubectl
uses: actions/cache@v4
id: kubectl-cache
with:
path: ~/.local/bin/kubectl
key: kubectl-${{ steps.kubectl-version.outputs.version }}-linux-amd64
- name: Install kubectl
if: steps.kubectl-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/.local/bin
curl -LO "https://dl.k8s.io/release/${{ steps.kubectl-version.outputs.version }}/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl ~/.local/bin/
- name: Add kubectl to PATH
run: echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Extract Dagger version
id: dagger-version
run: |
DAGGER_IMAGE=$(kubectl get pod --selector=name=dagger-dagger-helm-engine --namespace=dagger -o jsonpath='{.items[0].spec.containers[0].image}')
DAGGER_VERSION="${DAGGER_IMAGE##*:v}"
echo "version=$DAGGER_VERSION" >> "$GITHUB_OUTPUT"
- name: Cache Dagger CLI
uses: actions/cache@v4
id: dagger-cache
with:
path: ~/.local/bin/dagger
key: dagger-${{ steps.dagger-version.outputs.version }}-linux-amd64
- name: Install Dagger CLI
if: steps.dagger-cache.outputs.cache-hit != 'true'
run: |
set -euo pipefail
DAGGER_VERSION="${{ steps.dagger-version.outputs.version }}"
BIN_DIR="$HOME/.local/bin"
# Try primary source first
if ! curl -fsSL https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION="$DAGGER_VERSION" BIN_DIR="$BIN_DIR" sh; then
echo "WARNING: Primary source (dl.dagger.io) failed, trying GitHub releases..."
# Fallback to GitHub releases
mkdir -p "$BIN_DIR"
DAGGER_URL="https://github.com/dagger/dagger/releases/download/v${DAGGER_VERSION}/dagger_v${DAGGER_VERSION}_linux_amd64.tar.gz"
echo "Downloading from: $DAGGER_URL"
curl -fsSL "$DAGGER_URL" | tar xz -C /tmp
mv /tmp/dagger "$BIN_DIR/dagger"
chmod +x "$BIN_DIR/dagger"
fi
# Verify installation
if [ ! -f "$BIN_DIR/dagger" ]; then
echo "ERROR: Dagger CLI installation failed"
exit 1
fi
"$BIN_DIR/dagger" version
- name: Get Dagger Engine Pod Name
run: |
DAGGER_ENGINE_POD_NAME="$(kubectl get pod --selector=name=dagger-dagger-helm-engine --namespace=dagger --output=jsonpath='{.items[0].metadata.name}')"
echo "_EXPERIMENTAL_DAGGER_RUNNER_HOST=kube-pod://$DAGGER_ENGINE_POD_NAME?namespace=dagger" >> "$GITHUB_ENV"
- name: Install Dagger module dependencies
working-directory: .dagger
run: bun install --frozen-lockfile
- name: Resolve PR number
id: pr-number
run: |
# For issue_comment events, the PR number is in github.event.issue.number
# For pull_request_review_comment events, it's in github.event.pull_request.number
PR_NUMBER="${{ github.event.issue.number || github.event.pull_request.number }}"
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
- name: Run Dagger interactive review
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Pass user-controlled inputs through environment variables for safety
# Dagger's env: prefix treats these as secrets, preventing injection
COMMENT_BODY: ${{ github.event.comment.body }}
COMMENT_PATH: ${{ github.event.comment.path }}
COMMENT_LINE: ${{ github.event.comment.line }}
COMMENT_DIFF_HUNK: ${{ github.event.comment.diff_hunk }}
PR_NUMBER: ${{ steps.pr-number.outputs.number }}
run: |
ARGS=(
--source=.
--github-token=env:GH_TOKEN
--claude-oauth-token=env:CLAUDE_CODE_OAUTH_TOKEN
--pr-number="$PR_NUMBER"
--comment-body=env:COMMENT_BODY
)
# Add optional context for review comments (using env vars for safety)
if [ -n "$COMMENT_PATH" ]; then
ARGS+=(--comment-path="$COMMENT_PATH")
fi
if [ -n "$COMMENT_LINE" ]; then
ARGS+=(--comment-line="$COMMENT_LINE")
fi
if [ -n "$COMMENT_DIFF_HUNK" ]; then
ARGS+=(--comment-diff-hunk="$COMMENT_DIFF_HUNK")
fi
dagger call code-review-interactive "${ARGS[@]}"