Running Unsnag in CI
In CI, Unsnag answers one question for each pull request: does this change make the CLI harder for Agents? It runs the Benchmark, compares the Report with the last Report from main (the Baseline), and exits 1 when the gate trips, which fails the build.
The workflow
Copy this file into your repository as it is:
name: unsnag
on:
push:
branches: [main]
pull_request:
jobs:
unsnag:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
actions: read # to download main's last Report
steps:
- uses: actions/checkout@v4
- name: Install Unsnag
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install pimlicolabs/tap/unsnag
echo "$(brew --prefix)/bin" >> "$GITHUB_PATH"
- name: Download the Baseline, main's last Report
env:
GH_TOKEN: ${{ github.token }}
run: |
id=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=unsnag-report&per_page=100" \
--jq '[.artifacts[] | select(.workflow_run.head_branch == "main" and .workflow_run.head_repository_id == .workflow_run.repository_id and (.expired | not))][0].id // empty')
if [ -z "$id" ]; then
echo "No Report from main yet: this Report has no Baseline."
exit 0
fi
gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$id/zip" > unsnag-baseline.zip
unzip -q unsnag-baseline.zip -d unsnag-baseline
echo "UNSNAG_BASELINE=unsnag-baseline" >> "$GITHUB_ENV"
- name: Run the Benchmark
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
run: unsnag run ${UNSNAG_BASELINE:+--baseline "$UNSNAG_BASELINE"}
- name: Summarize the Report
id: report
if: ${{ !cancelled() }}
run: |
if id=$(unsnag report --json | jq -er '.data.id'); then
echo "folder=unsnag/reports/$id" >> "$GITHUB_OUTPUT"
{ echo '```'; unsnag report "$id" --no-color; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
fi
- name: Keep the Report
if: ${{ !cancelled() && steps.report.outputs.folder != '' }}
uses: actions/upload-artifact@v4
with:
name: unsnag-report
path: ${{ steps.report.outputs.folder }}
retention-days: 90Then add your OpenRouter key as a repository secret named OPENROUTER_API_KEY (Settings → Secrets and variables → Actions). OPENROUTER_API_KEY in the environment wins over any stored key, so nothing else is needed. If your Benchmark lists secrets, build or Run, add each one to the repository's secrets too, and to the Run the Benchmark step's env.
What each step does
- Install Unsnag from Pimlico's Homebrew tap, which GitHub's Ubuntu runners can use (Homebrew is installed but not on
PATH). The runners also have Docker, which every Run needs. The tap's formula ships with Unsnag's first release. - Download the Baseline. Each run of this workflow keeps its Report as an artifact named
unsnag-report. This step finds the newest one from a push tomainin this repository (not a fork's branch that happens to be calledmain) and unpacks it: a Report folder. On the very first run there is none, and the Report runs without a Baseline. - Run the Benchmark, compared with that Report through
--baseline. The comparison matches Cells by Scenario content, Agent and Context Condition, so it holds even though the Baseline was run on another machine.unsnag runexits 1 when the Report's status isn'tok, which fails the job. - Summarize the Report on the run's summary page, even when the Run step failed.
unsnag reportprints the same summary asrun: the Scenario × Agent grid, the Findings, the Runs that didn't pass, a note on the Baseline, and the verdict (gate, counts, success, time and cost) on the last line. - Keep the Report as the
unsnag-reportartifact, so a pull request's Report can be inspected (download it and open itsindex.html), and somain's becomes the next Baseline.
Pushes to main run the same steps: each main Report is compared with the previous one, so a regression that slips in shows on main too.
What fails the build
The gate decides, once the Runs finish, and its result is the Report's status:
| Status | When |
|---|---|
regressed | a Scenario × Context Condition row, or a headline rate, regressed against the Baseline |
new_finding | a new Finding that blocks Runs (only with gate: { new_finding: true }) |
success_below | the success rate is below gate: { success_below: <fraction> } |
inconclusive | more than 20% of the Runs errored, so the Report can't be trusted |
incomplete | the Report budget ran out before every Run started |
error | the Report couldn't run, for example a Scenario failed verify |
Each exits 1. Configure the gate in gate:
gate: { regressed: true, new_finding: true, success_below: 0.6 }A row is regressed only when the drop passes Fisher's exact test with Benjamini–Hochberg correction (q = 0.10), so noise doesn't fail builds: 15/15 → 13/15 is not a regression, 15/15 → 10/15 is. The comparison lists confounders first: a different Agent version, environment hash or analyzer version between the two Reports, any of which can move results without your change.
Keeping CI affordable
Every pull request pays for a full Report. To spend less:
- Run pull requests on a label instead of on every push: replace
pull_request:withpull_request: { types: [labeled] }and addif: github.event_name == 'push' || github.event.label.name == 'unsnag'to the job. - Cap each Report with
budget.report(anincompleteReport fails the job, so set it above the usual spend). A CI runner's Report store starts empty, sounsnag runestimates from the models' prices for a typical Run, not from your Scenarios' earlier Runs: the budget is what caps the spend. - Narrow the Runs:
unsnag run --tag smokewith asmoketag on a few Scenarios for pull requests, and the full Benchmark onmain. A partial Report compares only the Cells it ran.
See cost control for the budgets.
With a Project in the App
When your CLI has a Project in the App, CI can put each Report there, beside the ones the App runs, where the whole team can read it:
- In your repository, run
unsnag link <organization>/<project>(the two names in the Project's address in the App) and commit theunsnag/project.yamlit writes. CI's checkout is then linked. - In the Project's settings, under CLI and tokens, make a token for CI. It is shown once, reaches that Project only, and acts for nobody. Add it as a repository secret named
UNSNAG_TOKEN. - Give it to the step that runs the Benchmark:
- name: Run the Benchmark
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
UNSNAG_TOKEN: ${{ secrets.UNSNAG_TOKEN }}
run: unsnag run ${UNSNAG_BASELINE:+--baseline "$UNSNAG_BASELINE"}A linked unsnag run runs the Project's latest saved Benchmark version, not a unsnag/benchmark.yaml in the repository (make yours the Project's with unsnag import first). It still runs on the CI machine, with the workflow's OpenRouter key and the secrets in its environment, so the Benchmark's secrets go into the step's env as before. The Report goes into the App as it runs; an upload that fails warns and never fails the job. The rest of the workflow is unchanged: the Report is kept in unsnag/reports/, compared with the Baseline and gated as above.
To try every release without a workflow at all, turn on the Release trigger in the Project's settings instead: when a tag matching its pattern is pushed, the App runs a Report on a machine of its own, within the budget cap the trigger requires.
Without GitHub Actions
Any CI with Docker works the same way: install Unsnag, set OPENROUTER_API_KEY, run unsnag run, and keep the Report folder unsnag/reports/<id>/ (the id is in unsnag report --json). --baseline takes a Report folder, an id, or the URL of a .tar.gz of a Report folder, which Unsnag downloads and unpacks into unsnag/.cache/reports/.