Skip to content

Commit 7314a18

Browse files
committed
test(eval): exercise github actions reporter
1 parent 91930ec commit 7314a18

6 files changed

Lines changed: 1812 additions & 16 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: GitHub Actions reporter example
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
reporter-example:
12+
runs-on: ubuntu-latest
13+
env:
14+
CARGO_NET_GIT_FETCH_WITH_CLI: true
15+
steps:
16+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
17+
- name: Configure git auth for private dependencies
18+
run: |
19+
token="${BT_GITHUB_TOKEN:-$GITHUB_TOKEN}"
20+
git config --global url."https://x-access-token:${token}@github.com/".insteadOf "https://github.com/"
21+
env:
22+
BT_GITHUB_TOKEN: ${{ secrets.BT_GITHUB_TOKEN }}
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
- name: Install Rust
25+
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
26+
with:
27+
toolchain: 1.92.0
28+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
29+
with:
30+
node-version: "22"
31+
- name: Enable pnpm
32+
run: |
33+
corepack enable
34+
corepack prepare pnpm@10.28.2 --activate
35+
- name: Install example dependencies
36+
run: pnpm install --dir examples/eval-reporters --frozen-lockfile
37+
- name: Build bt
38+
run: cargo build --bin bt
39+
- name: Exercise the GitHub Actions reporter
40+
shell: bash
41+
run: |
42+
set +e
43+
output=$(cd examples/eval-reporters && ../../target/debug/bt eval \
44+
--no-send-logs \
45+
--reporter=github-actions \
46+
github-actions.eval.ts 2>&1)
47+
status=$?
48+
set -e
49+
50+
printf '%s\n' "$output"
51+
grep -F "::error title=case " <<<"$output" \
52+
| grep -F "errored::intentional error from the GitHub Actions reporter example"
53+
test "$status" -ne 0

examples/eval-reporters/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Eval reporter examples
2+
3+
## GitHub Actions
4+
5+
Install this example's dependencies, build `bt`, and run:
6+
7+
```bash
8+
pnpm install --dir examples/eval-reporters
9+
cargo build --bin bt
10+
cd examples/eval-reporters
11+
../../target/debug/bt eval --no-send-logs \
12+
--reporter=github-actions \
13+
github-actions.eval.ts
14+
```
15+
16+
The second case intentionally throws. In GitHub Actions, the reporter emits an `::error` workflow command so the case appears as an annotation. The command exits non-zero because the eval contains an errored case; this is expected for this example.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Eval } from "braintrust";
2+
3+
type Input = {
4+
message: string;
5+
shouldError: boolean;
6+
};
7+
8+
Eval("reporter-example", {
9+
evalName: "github-actions-reporter-example",
10+
data: (): Array<{ input: Input; expected: string }> => [
11+
{
12+
input: { message: "successful case", shouldError: false },
13+
expected: "successful case",
14+
},
15+
{
16+
input: { message: "annotated case", shouldError: true },
17+
expected: "annotated case",
18+
},
19+
],
20+
task: ({ message, shouldError }: Input): string => {
21+
if (shouldError) {
22+
throw new Error("intentional error from the GitHub Actions reporter example");
23+
}
24+
return message;
25+
},
26+
scores: [
27+
({ output, expected }: { output: string; expected: string }): number =>
28+
output === expected ? 1 : 0,
29+
],
30+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "bt-eval-reporter-examples",
3+
"private": true,
4+
"type": "module",
5+
"dependencies": {
6+
"braintrust": "2.2.2"
7+
},
8+
"devDependencies": {
9+
"tsx": "4.23.0"
10+
}
11+
}

0 commit comments

Comments
 (0)