-
Notifications
You must be signed in to change notification settings - Fork 5.6k
445 lines (426 loc) · 19.6 KB
/
Copy pathci-eval.yml
File metadata and controls
445 lines (426 loc) · 19.6 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
name: ci-workflow-eval
on:
issue_comment:
types: [created]
permissions:
contents: read
concurrency:
group: >-
${{
github.repository == 'dotnet/runtime' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER","MEMBER"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/ci-scan eval' || startsWith(github.event.comment.body, '/ci-scan eval ') ||
github.event.comment.body == '/ci-fix eval' || startsWith(github.event.comment.body, '/ci-fix eval ') ||
github.event.comment.body == '/ci-feedback eval' || startsWith(github.event.comment.body, '/ci-feedback eval ') ||
github.event.comment.body == '/ci-eval' || startsWith(github.event.comment.body, '/ci-eval ')
) &&
format('ci-workflow-eval-{0}', github.event.issue.number) ||
format('ci-workflow-eval-ignored-{0}', github.run_id)
}}
cancel-in-progress: true
jobs:
acknowledge:
if: >-
github.repository == 'dotnet/runtime' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER","MEMBER"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/ci-scan eval' || startsWith(github.event.comment.body, '/ci-scan eval ') ||
github.event.comment.body == '/ci-fix eval' || startsWith(github.event.comment.body, '/ci-fix eval ') ||
github.event.comment.body == '/ci-feedback eval' || startsWith(github.event.comment.body, '/ci-feedback eval ') ||
github.event.comment.body == '/ci-eval' || startsWith(github.event.comment.body, '/ci-eval ')
)
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
statuses: write
steps:
- name: Set pending status
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { owner, repo } = context.repo;
const { data: pr } = await github.rest.pulls.get({
owner, repo, pull_number: context.issue.number,
});
await github.rest.repos.createCommitStatus({
owner, repo, sha: pr.head.sha, state: 'pending',
context: 'ci-workflow-eval',
target_url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`,
description: 'CI workflow eval is running',
});
- name: Acknowledge the command
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { owner, repo } = context.repo;
await github.rest.reactions.createForIssueComment({
owner, repo, comment_id: context.payload.comment.id, content: 'eyes',
});
pat_pool:
if: >-
github.repository == 'dotnet/runtime' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER","MEMBER"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/ci-scan eval' || startsWith(github.event.comment.body, '/ci-scan eval ') ||
github.event.comment.body == '/ci-fix eval' || startsWith(github.event.comment.body, '/ci-fix eval ') ||
github.event.comment.body == '/ci-feedback eval' || startsWith(github.event.comment.body, '/ci-feedback eval ') ||
github.event.comment.body == '/ci-eval' || startsWith(github.event.comment.body, '/ci-eval ')
)
runs-on: ubuntu-latest
environment: copilot-pat-pool
permissions: {}
outputs:
pat_number: ${{ steps.select-pat-number.outputs.copilot_pat_number }}
steps:
- name: Select Copilot token from pool
id: select-pat-number
env:
COPILOT_PAT_0: ${{ secrets.COPILOT_PAT_0 }}
COPILOT_PAT_1: ${{ secrets.COPILOT_PAT_1 }}
COPILOT_PAT_2: ${{ secrets.COPILOT_PAT_2 }}
COPILOT_PAT_3: ${{ secrets.COPILOT_PAT_3 }}
COPILOT_PAT_4: ${{ secrets.COPILOT_PAT_4 }}
COPILOT_PAT_5: ${{ secrets.COPILOT_PAT_5 }}
COPILOT_PAT_6: ${{ secrets.COPILOT_PAT_6 }}
COPILOT_PAT_7: ${{ secrets.COPILOT_PAT_7 }}
COPILOT_PAT_8: ${{ secrets.COPILOT_PAT_8 }}
COPILOT_PAT_9: ${{ secrets.COPILOT_PAT_9 }}
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
run: |
PAT_NUMBERS=()
PAT_VALUES=(
"$COPILOT_PAT_0" "$COPILOT_PAT_1" "$COPILOT_PAT_2" "$COPILOT_PAT_3" "$COPILOT_PAT_4"
"$COPILOT_PAT_5" "$COPILOT_PAT_6" "$COPILOT_PAT_7" "$COPILOT_PAT_8" "$COPILOT_PAT_9"
)
for i in {0..9}; do
token="${PAT_VALUES[$i]}"
if [ -n "$token" ]; then
response="$RUNNER_TEMP/copilot-pat-${i}.json"
if ! status=$(curl --silent --write-out '%{http_code}' \
--header "Authorization: Bearer $token" \
--header "Accept: application/vnd.github+json" \
--output "$response" \
https://api.github.com/user); then
status=000
fi
if [ "$status" = 200 ]; then
PAT_NUMBERS+=("${i}")
else
echo "::warning::Ignoring COPILOT_PAT_${i}: authentication check failed (HTTP ${status})."
fi
rm -f "$response"
fi
done
if [ ${#PAT_NUMBERS[@]} -eq 0 ]; then
response="$RUNNER_TEMP/copilot-github-token.json"
if [ -n "$COPILOT_GITHUB_TOKEN" ] &&
status=$(curl --silent --write-out '%{http_code}' \
--header "Authorization: Bearer $COPILOT_GITHUB_TOKEN" \
--header "Accept: application/vnd.github+json" \
--output "$response" \
https://api.github.com/user) &&
[ "$status" = 200 ]; then
echo "::notice::No valid PAT pool entries found — using COPILOT_GITHUB_TOKEN."
rm -f "$response"
exit 0
fi
rm -f "$response"
echo "::error::No valid Copilot token is available."
exit 1
fi
PAT_INDEX=$(( RANDOM % ${#PAT_NUMBERS[@]} ))
PAT_NUMBER="${PAT_NUMBERS[$PAT_INDEX]}"
echo "Selected COPILOT_PAT_${PAT_NUMBER} from a pool of ${#PAT_NUMBERS[@]}."
echo "copilot_pat_number=${PAT_NUMBER}" >> "$GITHUB_OUTPUT"
eval:
needs: pat_pool
if: >-
github.repository == 'dotnet/runtime' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER","MEMBER"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/ci-scan eval' || startsWith(github.event.comment.body, '/ci-scan eval ') ||
github.event.comment.body == '/ci-fix eval' || startsWith(github.event.comment.body, '/ci-fix eval ') ||
github.event.comment.body == '/ci-feedback eval' || startsWith(github.event.comment.body, '/ci-feedback eval ') ||
github.event.comment.body == '/ci-eval' || startsWith(github.event.comment.body, '/ci-eval ')
)
runs-on: ubuntu-latest
environment: copilot-pat-pool
timeout-minutes: 120
permissions:
contents: read
issues: read
pull-requests: read
outputs:
guard_run: ${{ steps.guard.outputs.run }}
guard_reason: ${{ steps.guard.outputs.reason }}
head_sha: ${{ steps.guard.outputs.head_sha }}
steps:
- name: Select the spec(s) from the command
id: sel
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
base=.github/workflows/evals
case "$COMMENT_BODY" in
"/ci-scan eval"|"/ci-scan eval "*) specs="$base/ci-failure-scan.eval.yaml" ;;
"/ci-fix eval"|"/ci-fix eval "*) specs="$base/ci-failure-fix.eval.yaml" ;;
"/ci-feedback eval"|"/ci-feedback eval "*) specs="$base/ci-failure-scan-feedback.eval.yaml" ;;
"/ci-eval"|"/ci-eval "*) specs="$base/ci-failure-scan.eval.yaml $base/ci-failure-fix.eval.yaml $base/ci-failure-scan-feedback.eval.yaml" ;;
*) specs="" ;;
esac
echo "specs=$specs" >> "$GITHUB_OUTPUT"
- name: Guard on fork and token
id: guard
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
COPILOT_GITHUB_TOKEN: >-
${{
needs.pat_pool.outputs.pat_number == '0' && secrets.COPILOT_PAT_0 ||
needs.pat_pool.outputs.pat_number == '1' && secrets.COPILOT_PAT_1 ||
needs.pat_pool.outputs.pat_number == '2' && secrets.COPILOT_PAT_2 ||
needs.pat_pool.outputs.pat_number == '3' && secrets.COPILOT_PAT_3 ||
needs.pat_pool.outputs.pat_number == '4' && secrets.COPILOT_PAT_4 ||
needs.pat_pool.outputs.pat_number == '5' && secrets.COPILOT_PAT_5 ||
needs.pat_pool.outputs.pat_number == '6' && secrets.COPILOT_PAT_6 ||
needs.pat_pool.outputs.pat_number == '7' && secrets.COPILOT_PAT_7 ||
needs.pat_pool.outputs.pat_number == '8' && secrets.COPILOT_PAT_8 ||
needs.pat_pool.outputs.pat_number == '9' && secrets.COPILOT_PAT_9 ||
secrets.COPILOT_GITHUB_TOKEN
}}
with:
script: |
const { owner, repo } = context.repo;
const { data: pr } = await github.rest.pulls.get({
owner, repo, pull_number: context.issue.number,
});
const headRepo = pr.head.repo ? pr.head.repo.full_name : null;
const base = `${owner}/${repo}`;
core.setOutput('head_sha', pr.head.sha);
if (headRepo !== base) {
core.setOutput('run', 'false');
core.setOutput('reason',
`Refusing to run: the PR head \`${headRepo || 'unknown'}\` is a fork. ` +
`This eval checks out and runs untrusted PR content with a Copilot token, ` +
`so it is restricted to branches on \`${base}\`.`);
return;
}
if (!process.env.COPILOT_GITHUB_TOKEN) {
core.setOutput('run', 'false');
core.setOutput('reason',
'Skipped: no Copilot token available (COPILOT_PAT_* / COPILOT_GITHUB_TOKEN).');
return;
}
core.setOutput('run', 'true');
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
if: steps.guard.outputs.run == 'true'
with:
persist-credentials: false
- name: Preserve the trusted eval specs
if: steps.guard.outputs.run == 'true'
env:
SPECS: ${{ steps.sel.outputs.specs }}
run: |
mkdir -p "$RUNNER_TEMP/trusted-evals"
for spec in $SPECS; do
cp "$spec" "$RUNNER_TEMP/trusted-evals/$(basename "$spec")"
done
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
if: steps.guard.outputs.run == 'true'
with:
node-version: "22"
- name: Install the Vally CLI
if: steps.guard.outputs.run == 'true'
run: |
mkdir -p "$RUNNER_TEMP/trusted-evals-tooling"
cp .github/workflows/evals/package.json .github/workflows/evals/package-lock.json \
"$RUNNER_TEMP/trusted-evals-tooling/"
npm ci --prefix "$RUNNER_TEMP/trusted-evals-tooling" \
--registry=https://registry.npmjs.org --replace-registry-host=never
echo "$RUNNER_TEMP/trusted-evals-tooling/node_modules/.bin" >> "$GITHUB_PATH"
- name: Check out the PR head
if: steps.guard.outputs.run == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh pr checkout ${{ github.event.issue.number }}
- name: Restore the trusted eval specs
if: steps.guard.outputs.run == 'true'
env:
SPECS: ${{ steps.sel.outputs.specs }}
run: |
for spec in $SPECS; do
rm -f -- "$spec"
cp -- "$RUNNER_TEMP/trusted-evals/$(basename "$spec")" "$spec"
done
- name: Lint the selected spec(s)
if: steps.guard.outputs.run == 'true'
env:
SPECS: ${{ steps.sel.outputs.specs }}
run: |
for spec in $SPECS; do
vally lint --eval-spec "$spec" --strict
done
- name: Run the eval(s)
if: steps.guard.outputs.run == 'true'
id: run
env:
COPILOT_GITHUB_TOKEN: >-
${{
needs.pat_pool.outputs.pat_number == '0' && secrets.COPILOT_PAT_0 ||
needs.pat_pool.outputs.pat_number == '1' && secrets.COPILOT_PAT_1 ||
needs.pat_pool.outputs.pat_number == '2' && secrets.COPILOT_PAT_2 ||
needs.pat_pool.outputs.pat_number == '3' && secrets.COPILOT_PAT_3 ||
needs.pat_pool.outputs.pat_number == '4' && secrets.COPILOT_PAT_4 ||
needs.pat_pool.outputs.pat_number == '5' && secrets.COPILOT_PAT_5 ||
needs.pat_pool.outputs.pat_number == '6' && secrets.COPILOT_PAT_6 ||
needs.pat_pool.outputs.pat_number == '7' && secrets.COPILOT_PAT_7 ||
needs.pat_pool.outputs.pat_number == '8' && secrets.COPILOT_PAT_8 ||
needs.pat_pool.outputs.pat_number == '9' && secrets.COPILOT_PAT_9 ||
secrets.COPILOT_GITHUB_TOKEN
}}
GH_TOKEN: ${{ github.token }}
# The GitHub MCP server reads this name from its Docker container.
GITHUB_PERSONAL_ACCESS_TOKEN: ${{ github.token }}
SPECS: ${{ steps.sel.outputs.specs }}
run: |
workdir="$RUNNER_TEMP/vally"
mkdir -p "$workdir"
report="$workdir/report.md"
: > "$report"
rc=0
for spec in $SPECS; do
name="$(basename "$spec" .eval.yaml)"
echo "## $name" >> "$report"
if vally eval --eval-spec "$spec" --skill-dir .github/workflows \
--workspace "$workdir/ws-$name" --output-dir "$workdir/out-$name" > "$workdir/log-$name.txt" 2>&1; then
echo "✅ passed" >> "$report"
else
rc=1
echo "❌ failed" >> "$report"
fi
shopt -s nullglob
results=("$workdir/out-$name"/*/eval-results.md)
if [ ${#results[@]} -eq 1 ]; then
{ echo; echo '<details><summary>details</summary>'; echo; cat "${results[0]}"; echo; echo '</details>'; } >> "$report"
elif [ ${#results[@]} -gt 1 ]; then
echo "_details omitted: unexpected result files_" >> "$report"
fi
echo >> "$report"
done
exit $rc
- name: Upload the report
if: always() && steps.guard.outputs.run == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ci-workflow-eval-report
path: ${{ runner.temp }}/vally/report.md
if-no-files-found: ignore
retention-days: 1
report:
needs: [pat_pool, eval]
if: >-
always() &&
needs.pat_pool.result != 'skipped' &&
github.repository == 'dotnet/runtime' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER","MEMBER"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/ci-scan eval' || startsWith(github.event.comment.body, '/ci-scan eval ') ||
github.event.comment.body == '/ci-fix eval' || startsWith(github.event.comment.body, '/ci-fix eval ') ||
github.event.comment.body == '/ci-feedback eval' || startsWith(github.event.comment.body, '/ci-feedback eval ') ||
github.event.comment.body == '/ci-eval' || startsWith(github.event.comment.body, '/ci-eval ')
)
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
statuses: write
steps:
- name: Download the report
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
continue-on-error: true
with:
name: ci-workflow-eval-report
path: ${{ runner.temp }}/vally
- name: Post the report
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
GUARD_RUN: ${{ needs.eval.outputs.guard_run }}
GUARD_REASON: ${{ needs.eval.outputs.guard_reason }}
with:
script: |
const fs = require('fs');
const path = require('path');
const marker = '<!-- ci-workflow-eval -->';
let body;
if (process.env.GUARD_RUN === 'true') {
const header = '> [!NOTE]\n> AI/Copilot-generated eval report (Vally), triggered by a maintainer eval command.\n\n';
let report = '_eval report unavailable_';
try {
report = fs.readFileSync(path.join(process.env.RUNNER_TEMP, 'vally', 'report.md'), 'utf8');
} catch {
core.warning('The eval report artifact is unavailable.');
}
body = `${marker}\n${header}${report}`;
} else {
body = `${marker}\n${process.env.GUARD_REASON || '_eval skipped_'}`;
}
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number, per_page: 100 });
const existing = comments.find(c => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number, body });
}
- name: Set final status
if: always()
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
EVAL_RESULT: ${{ needs.eval.result }}
GUARD_RUN: ${{ needs.eval.outputs.guard_run }}
HEAD_SHA: ${{ needs.eval.outputs.head_sha }}
with:
script: |
const fs = require('fs');
const path = require('path');
let report = '';
let reportUnavailable = false;
try {
report = fs.readFileSync(path.join(process.env.RUNNER_TEMP, 'vally', 'report.md'), 'utf8');
} catch {
reportUnavailable = true;
}
const { owner, repo } = context.repo;
const evalResult = process.env.EVAL_RESULT;
const authenticationFailed = report.includes('Authentication failed');
let headSha = process.env.HEAD_SHA;
if (!headSha) {
const { data: pr } = await github.rest.pulls.get({
owner, repo, pull_number: context.issue.number,
});
headSha = pr.head.sha;
}
const passed = process.env.GUARD_RUN === 'true' &&
evalResult === 'success' &&
!report.includes('❌ failed') &&
!reportUnavailable;
const failed = process.env.GUARD_RUN === 'true' &&
evalResult === 'failure' &&
!authenticationFailed &&
!reportUnavailable;
await github.rest.repos.createCommitStatus({
owner, repo, sha: headSha,
state: passed ? 'success' : failed ? 'failure' : 'error',
context: 'ci-workflow-eval',
target_url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`,
description: passed ? 'All selected evals passed' :
failed ? 'One or more selected evals failed' :
'CI workflow eval could not complete',
});