<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# Set up CI

> Add the KeepSnappy job to your CI by hand, set its timeout, see what init writes, and choose a required or an advisory check.

In CI, one job runs `keepsnappy run --upload`. It reads `keepsnappy.yml`, runs your journeys, and uploads the measurements as one session. [Getting started](https://keepsnappy.com/docs/getting-started.md) has init write it. This page has [a complete workflow](#a-complete-workflow) to write by hand, its timeout, and [required or advisory checks](#required-or-advisory-checks). Every `keepsnappy.yml` setting, the flags of `keepsnappy run` and its exit codes are on [keepsnappy.yml and run flags](https://keepsnappy.com/docs/settings.md).

## Budget the first session

Each journey runs 5 times per session by default, from the CLI’s `repetitions` default. A session is one job, not one run. Estimate the job timeout as build + repetitions × journey time + overhead. Journey time is one pass of all selected journeys; with a command runner the whole command (even a 68-file suite) is one journey. Build and install time count against the CI timeout, but are not measured journey time. Overhead includes dependency setup, [activation](https://keepsnappy.com/docs/glossary.md#activation) and [flush](https://keepsnappy.com/docs/glossary.md#flush), upload and up to 10 minutes of waiting for the result with `--wait`.

The starter workflows allow 20 + 5 × 10 + 20 = 90 minutes: a 20-minute build, a 10-minute pass of the selected journeys and 20 minutes for setup, upload and the wait for the result. That exceeds 60 minutes, so init and the matching examples use `timeout-minutes: 90`. Init raises shorter numeric job timeouts, preserves larger ones, and asks you to check expression-based timeouts. This is a planning example, not a measured promise: time your own build and journeys and leave headroom. Longer suites need a larger timeout or a smaller selection. Existing workflows already written by init are yours to update.

For a shorter first session, run `npx --no-install keepsnappy run --repeat 3 --upload --wait` after building and installing the app, or put a smaller repeatable selection in `flows.paths` (Maestro) or `flows.command` (your runner’s file/spec filter). For that sample, 20 + 3 × 10 + 20 = 70 minutes. At least 3 valid runs doing the same work are still needed for comparison; a lower requested count does not change the rules. Three sessions of main remain separate jobs, each with its own build and runs.

Init warns when your suite looks too big for the job's timeout. Its estimate assumes one minute per test file or Maestro flow and does not read your runner's filters, so a missing warning doesn't prove the suite is small: time your own job.

<span id="keepsnappyyml"></span><span id="a-custom-simulator-set"></span>A full `keepsnappy.yml` with every setting, and [a custom simulator set](https://keepsnappy.com/docs/settings.md#a-custom-simulator-set), are on [keepsnappy.yml and run flags](https://keepsnappy.com/docs/settings.md#keepsnappyyml).

## A complete workflow

`keepsnappy init` writes this kind of file from your own end-to-end job. To write it by hand, put `keepsnappy.yml` in the repository root ([keepsnappy.yml](https://keepsnappy.com/docs/settings.md#keepsnappyyml)), then add the workflow. It runs on every pull request, on every push to `main`, every night at 03:00 UTC, and by hand from the **Actions** tab.

```yaml
# .github/workflows/keepsnappy.yml
name: KeepSnappy
on:
  pull_request:
  push:
    branches: [main] # your default branch
  schedule:
    - cron: '0 3 * * *'
  workflow_dispatch:
jobs:
  keepsnappy:
    runs-on: macos-15
    timeout-minutes: 90
    env:
      KEEPSNAPPY: '1'
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: '24'
      - run: npm ci
      - name: Boot a simulator
        run: |
          UDID=$(xcrun simctl list devices --json | jq -r '[.devices[][] | select(.name == "iPhone 16" and .isAvailable)][0].udid')
          xcrun simctl boot "$UDID" || true
          xcrun simctl bootstatus "$UDID" -b
          echo "SIMULATOR_UDID=$UDID" >> "$GITHUB_ENV"
      - name: Build and install the KeepSnappy build
        run: |
          npx expo prebuild --platform ios
          npx expo run:ios --configuration Release --device "$SIMULATOR_UDID"
      - name: Install Maestro
        run: |
          curl -fsSL "https://get.maestro.mobile.dev" | bash
          echo "$HOME/.maestro/bin" >> "$GITHUB_PATH"
      - name: Measure with KeepSnappy
        env:
          KEEPSNAPPY_KEY: ${{ secrets.KEEPSNAPPY_KEY }}
        run: >
          npx @keepsnappy/agent run --upload --wait
          --device "$SIMULATOR_UDID"
          --commit ${{ github.event.pull_request.head.sha || github.sha }}
```

Each job is one session. The tool reads the branch from GitHub. To try the measure step on your machine, add `--branch` with your branch name.

- The checkout takes the pull request’s own commit, not GitHub’s merge commit, and `--commit` reports that same commit.
- `fetch-depth: 0` fetches the full history, so KeepSnappy can find where the branch left `main`.
- The build and the measurement both use the simulator the first step booted.
- The nightly run keeps the history of `main` fresh.
- Keep the Install Maestro step if the workflow runs Maestro through `flows.command` or after `--`, as well as with `flows.runner` set to `maestro`. Omit it when the test command does not use Maestro.

With pnpm or yarn, replace the `npm ci` step. A bare React Native app (no `expo prebuild`) links the SDK's native module after the install:

```yaml
jobs:
  keepsnappy:
    steps:
      # pnpm: the action reads the pnpm version from packageManager in package.json
      - uses: pnpm/action-setup@v4
      - run: pnpm install --frozen-lockfile
      # yarn 2 or newer, instead
      - run: yarn install --immutable
      # bare React Native, after the install
      - run: cd ios && pod install
```

A bare React Native app also replaces the two build lines with the `xcodebuild` and `xcrun simctl install` lines of [Try it on your Mac](https://keepsnappy.com/docs/on-your-mac.md#build-and-install-the-measuring-build), with `"$SIMULATOR_UDID"` as the simulator.

Commit `keepsnappy.yml`, `metro.config.js`, `app.json`, `package.json` and its lock file, and the workflow. A bare React Native app also commits `ios/Podfile.lock`. Add `keepsnappy-out/` and `.keepsnappy/` to `.gitignore`: each session writes its runs there.

In a repository set up by init, `@keepsnappy/agent` is a dev dependency, so `npx --no-install keepsnappy run` works. By hand, either add it as a dev dependency ([Install the CLI](https://keepsnappy.com/docs/install.md#the-command-line-tool)) or keep `npx @keepsnappy/agent run` as above.

These commands always use the latest release. To pin a version in CI, add it after the package name, e.g. `@keepsnappy/agent@<version>`. The [compatibility table](https://keepsnappy.com/docs/install.md#versions-that-work-together) lists the versions that work together.

[How a result is decided](https://keepsnappy.com/docs/results.md) says what the job prints after the upload and when the result appears.

## What init writes in your workflow

Init writes a separate `.github/workflows/keepsnappy.yml` from your own end-to-end job, with two changes: `KEEPSNAPPY: '1'` in the job's `env`, so the build sees it, and your test command wrapped in `keepsnappy run`.

```yaml
jobs:
  keepsnappy:
    env:
      KEEPSNAPPY: '1'
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          fetch-depth: 0
      - run: npx expo run:ios --configuration Release
      - run: npx --no-install keepsnappy run --upload --wait --commit ${{ github.event.pull_request.head.sha || github.sha }} -- <your end-to-end test command>
```

This shows only the lines that change: the whole file, with the simulator, Maestro and the key's `env:`, is [above](#a-complete-workflow). Your existing workflows and app code are not touched. [Step markers](https://keepsnappy.com/docs/glossary.md#step-marker) in your tests are optional: results are correct without them.

Before init has run, `npx --no-install keepsnappy` does not exist: add `@keepsnappy/agent` as a dev dependency ([Install the CLI](https://keepsnappy.com/docs/install.md#the-command-line-tool)) or run `npx @keepsnappy/agent run`.

Init's workflow runs on pull requests, pushes to the default branch and by hand. It adds a nightly run at 02:17 UTC only if you answer yes when init asks, or pass `--nightly`. Otherwise, to keep `main` fresh when nothing is merged for a while, add a schedule under `on:` in `.github/workflows/keepsnappy.yml`, next to `pull_request`, `push` and `workflow_dispatch`. This runs it on `main` every night at 03:00 UTC, as the [complete workflow](#a-complete-workflow) does:

```yaml
on:
  schedule:
    - cron: '0 3 * * *'
```

## Builds that send their own measurements

<span id="android-and-browserstack"></span>The [complete workflow](#a-complete-workflow) is for the iOS simulator, where the `keepsnappy` command reads the measurements from the simulator. On Android, and on real phones on BrowserStack, the app sends its own. Its build needs two values in the build environment, never in `app.json`:

- `EXPO_PUBLIC_KEEPSNAPPY_KEY`: the [SDK key](https://keepsnappy.com/docs/glossary.md#sdk-key). It is a different key from the CI key, and the CI key can't read or make it.
- `EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL`: the API address.

**Setup**, step 1, in the dashboard shows both values, under **Builds that send their own measurements**. [SDK](https://keepsnappy.com/docs/sdk.md#the-build-switch) lists every build variable.

Some apps require a fresh [run token](https://keepsnappy.com/docs/glossary.md#run-token) on every upload from the SDK (`require_run_token`): a short-lived token that KeepSnappy gives each run when the CLI opens it. The SDK sends it in the `x-keepsnappy-run-token` header, so activate the app with the token of the current run. `run_token_required` means the token is missing. `run_token_expired` means you start a fresh run and activate the app again. When the CI key that made a token is revoked or expires, its tokens stop working for these apps too. Other apps upload with the SDK key alone.

### Android, on an emulator in your CI

Start with `keepsnappy init --detect`. If the plan names your Android emulator job, follow the steps it prints. If init cannot use the job, follow the manual setup in [Android](https://keepsnappy.com/docs/android.md#android-emulator). The e2e (e2e.com) Android template ([e2e](https://keepsnappy.com/docs/test-tools/e2e.md#ready-made-workflows)) sets `EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL` from the repository variable `KEEPSNAPPY_API`. [Make a Release build](https://keepsnappy.com/docs/sdk.md#make-a-release-build) has the Android build commands.

For an Android phone on a cable, see [Android](https://keepsnappy.com/docs/android.md#android-usb-phone).

### Real phones on BrowserStack

Real phones on BrowserStack, iOS or Android, run through the `farm` command, in place of `keepsnappy run`. During the pilot, the KeepSnappy team sets these runs up with you ([Real phones on BrowserStack](https://keepsnappy.com/docs/browserstack.md)).

<span id="flags-of-keepsnappy-run"></span><span id="exit-codes"></span>The flags of `keepsnappy run` and what each exit code means are on [keepsnappy.yml and run flags](https://keepsnappy.com/docs/settings.md#flags-of-keepsnappy-run).

## Required or advisory checks

This section explains `verdict_gate`; other pages link here. [Exit codes](https://keepsnappy.com/docs/settings.md#exit-codes) has every exit code.

During the pilot, keep `verdict_gate: advisory`, which init writes, and do not make the KeepSnappy check required: a blocking **Worse** then passes the check, and a false alarm is marked on the dashboard. With `verdict_gate: blocking` or no `verdict_gate`, that **Worse** leaves the check red, and a mark does not turn the check green ([False alarms](https://keepsnappy.com/docs/false-alarms.md)). With a CLI release that sends your gate setting, Slack, the dashboard and the MCP server then say `Would block the merge; advisory during the pilot, CI passes`.

The verdict gate fails only on blocking Worse, and only with `verdict_gate: blocking` or no `verdict_gate`: with `--upload --wait`, a blocking Worse on a pull request then exits `3`. With `verdict_gate: advisory` it exits `0` (below). Worse (not blocking), Slightly worse, Can’t tell and not judged pass. A verdict timeout is a separate failure (`4`); build, configuration and infrastructure errors can also fail the job.

To block merging, set `verdict_gate: blocking` in `keepsnappy.yml` (or leave the key out), keep `--upload --wait`, let the measurement step fail normally (no `continue-on-error`), and make the `keepsnappy` job in the KeepSnappy workflow a required status check in your GitHub branch protection rule or ruleset. If you renamed the workflow or job, select its actual check name.

For an advisory check, leave that check out of the required checks. Set `continue-on-error` to `true` on the measurement step if the workflow should continue after a measurement failure; this also tolerates its infrastructure errors and timeouts. Uploaded results still reach the dashboard. Without `--wait`, the result never affects the step’s exit code.

With `verdict_gate: advisory`, a blocking **Worse** passes the step (exit `0`). The job log says `Worse — advisory: the step passes (verdict_gate: advisory in keepsnappy.yml)`, `keepsnappy-result.json` records `gate` as `advisory`, and the job summary, the dashboard and Slack still say **Worse**. Infrastructure, configuration and verdict timeout still fail the step (`1`, `2`, `4`). `npx --no-install keepsnappy doctor --group app` shows the setting on the `config` line. A CLI older than the release that adds `verdict_gate` refuses the key as a configuration error (exit `2`): pin the CLI release that adds it.

Without [`act`](https://keepsnappy.com/docs/ai-act.md), the pull request shows only the check status: read the result on the workflow run’s **Summary** page, the dashboard or with `keepsnappy status`. A green check can include a Worse that does not block.

If the workflow uses `pr-comment`, run its phone and final commands and `act` in one GitHub Actions concurrency group per PR. Each job needs its turn to update the general comment. Disable cancellation of running jobs and let all pending jobs queue, or sequence the writers with job dependencies. The `act` run on a fix branch writes the source pull request's comment, so it uses the source pull request's group: the number is the `-pr<source>` ending of the fix branch's name, read in an earlier job as [act's guide](https://keepsnappy.com/docs/ai-act.md) shows.

## See also

- <span id="app-change-inputs"></span>How AI review skips the AI when the app did not change between the two builds: [AI review in CI](https://keepsnappy.com/docs/ai-review.md#app-change-inputs).
- <span id="testerarmy-e2e-on-github-actions"></span>Ready-made e2e workflows, for the iOS simulator and the Android emulator: [e2e](https://keepsnappy.com/docs/test-tools/e2e.md#ready-made-workflows).

Next: every `keepsnappy.yml` setting, the flags of `keepsnappy run` and its exit codes are on [keepsnappy.yml and run flags](https://keepsnappy.com/docs/settings.md).

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
