283 lines
10 KiB
YAML

name: Evals
on:
pull_request:
workflow_dispatch:
inputs:
suite:
description: 'Specific suite to run (leave empty for all)'
required: false
type: string
multi_model:
description: 'Run against multiple models'
required: false
default: false
type: boolean
skip_cache:
description: 'Skip Nx cache and re-run all suites'
required: false
default: false
type: boolean
concurrency:
group: evals-${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
check-paths:
name: Check Changed Paths
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.filter.outputs.evals }}
permissions:
contents: read
pull-requests: read
steps:
- uses: bullfrogsec/bullfrog@1831f79cce8ad602eef14d2163873f27081ebfb3 # v0.8.4
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Check for eval-related changes
id: filter
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
with:
filters: |
evals:
- 'packages/plugins/**'
- 'evals/**'
- '.github/workflows/evals.yml'
eval:
name: Run Evaluations
runs-on: ubuntu-latest
needs: check-paths
# Run if: paths changed OR workflow_dispatch (manual trigger)
if: needs.check-paths.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
pull-requests: write
steps:
- uses: bullfrogsec/bullfrog@1831f79cce8ad602eef14d2163873f27081ebfb3 # v0.8.4
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'npm'
- name: Install npm
env:
NPM_VERSION: ${{ vars.NPM_VERSION || '11.7.0' }}
# NPM_VERSION is a repository variable controlled by admins
# Safe to use because: (1) admin-controlled (2) validated by npm version parser
run: npm install -g "npm@$NPM_VERSION" # nosemgrep: uniswap.npm-package-in-action-not-pinned-to-commit-sha
- name: Install dependencies
run: npm ci --prefer-offline --no-audit
- name: Restore Nx cache
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: node_modules/.cache/nx
key: nx-evals-${{ runner.os }}-${{ github.sha }}
restore-keys: |
nx-evals-${{ runner.os }}-
- name: Run evaluations
id: eval
env:
# Support both API key and OAuth token authentication
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
SUITE_INPUT: ${{ github.event.inputs.suite }}
SKIP_CACHE: ${{ github.event.inputs.skip_cache }}
EVENT_NAME: ${{ github.event_name }}
run: |
# Verify required dependencies
command -v jq >/dev/null 2>&1 || { echo "::error::jq is required but not installed"; exit 1; }
command -v bc >/dev/null 2>&1 || { echo "::error::bc is required but not installed"; exit 1; }
# Build skip-cache flag
NX_CACHE_FLAG=""
if [ "$SKIP_CACHE" = "true" ]; then
NX_CACHE_FLAG="--skip-nx-cache"
echo "::notice::Nx cache skipped (manual override)"
fi
# Clear previous results so aggregation only counts suites that ran
rm -f evals/suites/*/results.json
# Run eval suites via Nx
# - PR: nx affected uses the project graph to run only suites whose
# plugin or eval dependencies changed (defaultBase: origin/main)
# - Manual (specific suite): nx run targets the exact suite
# - Manual (all): nx run-many runs all eval-suite-* projects
if [ -n "$SUITE_INPUT" ]; then
# Validate suite input (only alphanumeric, dash, and underscore allowed)
if ! echo "$SUITE_INPUT" | grep -qE '^[a-zA-Z0-9_-]+$'; then
echo "::error::Invalid suite name. Only alphanumeric, dash, and underscore allowed"
exit 1
fi
echo "::group::Running specific suite: $SUITE_INPUT"
# shellcheck disable=SC2086
npx nx run "eval-suite-$SUITE_INPUT:eval" $NX_CACHE_FLAG || true
echo "::endgroup::"
elif [ "$EVENT_NAME" = "workflow_dispatch" ]; then
echo "::group::Running all eval suites (manual trigger)"
# shellcheck disable=SC2086
npx nx run-many -t eval --projects='tag:type:eval-suite' $NX_CACHE_FLAG || true
echo "::endgroup::"
else
echo "::group::Running affected eval suites"
# shellcheck disable=SC2086
npx nx affected -t eval --exclude=evals $NX_CACHE_FLAG || true
echo "::endgroup::"
fi
# Aggregate results from suites that produced output
TOTAL_PASS=0
TOTAL_FAIL=0
TOTAL_COST=0
RESULTS_SUMMARY=""
SUITES_RAN=0
for results_file in evals/suites/*/results.json; do
[ -f "$results_file" ] || continue
suite_name=$(basename "$(dirname "$results_file")")
PASS=$(jq '.results.stats.successes // 0' "$results_file")
FAIL=$(jq '.results.stats.failures // 0' "$results_file")
COST=$(jq '.results.stats.totalCost // 0' "$results_file")
TOTAL_PASS=$((TOTAL_PASS + PASS))
TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
TOTAL_COST=$(echo "$TOTAL_COST + $COST" | bc -l)
SUITES_RAN=$((SUITES_RAN + 1))
RESULTS_SUMMARY="${RESULTS_SUMMARY}| ${suite_name} | ${PASS} | ${FAIL} | \$${COST} |\n"
done
if [ "$SUITES_RAN" -eq 0 ]; then
echo "No eval suites were affected"
echo "status=skipped" >> "$GITHUB_OUTPUT"
exit 0
fi
# Calculate pass rate
TOTAL=$((TOTAL_PASS + TOTAL_FAIL))
if [ "$TOTAL" -gt 0 ]; then
PASS_RATE=$(echo "scale=2; $TOTAL_PASS * 100 / $TOTAL" | bc -l)
else
PASS_RATE=0
fi
# Output summary
echo "## Eval Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Suite | Passed | Failed | Cost |" >> "$GITHUB_STEP_SUMMARY"
echo "|-------|--------|--------|------|" >> "$GITHUB_STEP_SUMMARY"
echo -e "$RESULTS_SUMMARY" >> "$GITHUB_STEP_SUMMARY"
echo "| **Total** | **$TOTAL_PASS** | **$TOTAL_FAIL** | **\$${TOTAL_COST}** |" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Pass Rate:** ${PASS_RATE}% ($SUITES_RAN suite(s) evaluated)" >> "$GITHUB_STEP_SUMMARY"
# Set outputs
echo "pass_rate=$PASS_RATE" >> "$GITHUB_OUTPUT"
echo "total_pass=$TOTAL_PASS" >> "$GITHUB_OUTPUT"
echo "total_fail=$TOTAL_FAIL" >> "$GITHUB_OUTPUT"
echo "total_cost=$TOTAL_COST" >> "$GITHUB_OUTPUT"
# Fail if below threshold (85%)
if [ "$TOTAL" -gt 0 ]; then
THRESHOLD=85
if (( $(echo "$PASS_RATE < $THRESHOLD" | bc -l) )); then
echo "::error::Pass rate ${PASS_RATE}% is below ${THRESHOLD}% threshold"
exit 1
fi
fi
echo "status=success" >> "$GITHUB_OUTPUT"
- name: Save Nx cache
if: always()
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: node_modules/.cache/nx
key: nx-evals-${{ runner.os }}-${{ github.sha }}
- name: Upload eval results
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: eval-results
path: evals/suites/*/results.json
if-no-files-found: ignore
retention-days: 30
- name: Comment on PR
if: github.event_name == 'pull_request' && steps.eval.outputs.status == 'success'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
PASS_RATE: ${{ steps.eval.outputs.pass_rate }}
TOTAL_PASS: ${{ steps.eval.outputs.total_pass }}
TOTAL_FAIL: ${{ steps.eval.outputs.total_fail }}
TOTAL_COST: ${{ steps.eval.outputs.total_cost }}
with:
script: |
const passRate = process.env.PASS_RATE;
const totalPass = process.env.TOTAL_PASS;
const totalFail = process.env.TOTAL_FAIL;
const totalCost = process.env.TOTAL_COST;
const body = `## Eval Results
| Metric | Value |
|--------|-------|
| Pass Rate | ${passRate}% |
| Passed | ${totalPass} |
| Failed | ${totalFail} |
| Inference Cost | $${totalCost} |
[View full results](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('## Eval Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}