twocents/open source

Automation

Check or publish a capture with a post-run script.

Use --exec to run a script after capture finishes. Snapbot invokes it directly, so the file must have executable permission and its shebang chooses the runtime:

pnpm capture --project-root /absolute/path/to/app \
  --config ./snapbot.json \
  --output ./snapbot-output \
  --exec ./scripts/publish-snapbot-run

Snapbot invokes the executable with the absolute summary.json path as its first argument. It also provides SNAPBOT_SUMMARY_PATH, SNAPBOT_OUTPUT_DIRECTORY, and SNAPBOT_PROJECT_ROOT. It runs after both successful and failed captures once a summary has been finalized. Configuration validation and output-directory failures occur earlier and do not invoke it. Its failure makes the command exit nonzero without changing the capture status in summary.json.

Use the script to upload screenshots, send results to a review dashboard, or check them in CI with your own credentials.

Fail a run that has warnings

Create scripts/check-snapbot-run.mjs in your app and make it executable with chmod +x scripts/check-snapbot-run.mjs. This example intentionally rejects warnings as well as failed captures; choose the policy appropriate for your app.

#!/usr/bin/env node
import { readFile } from "node:fs/promises";

const summary = JSON.parse(await readFile(process.argv[2], "utf8"));
if (summary.status !== "success" || summary.app?.warning) {
  console.error(summary.error ?? summary.app?.error ?? summary.app?.warning ?? "Capture failed");
  process.exitCode = 1;
} else {
  console.log(`Checked ${summary.app?.screenshots.length ?? 0} screenshots`);
}

Run from the Snapbot checkout:

pnpm capture --project-root /absolute/path/to/app \
  --config snapbot.json --output snapbot-output/run-002 \
  --exec scripts/check-snapbot-run.mjs

The callback runs with the project root as its working directory. It receives one argument, the absolute summary path, and inherits the process environment plus the three SNAPBOT_* variables listed above. Keep credential handling in your own consumer and inspect artifacts before sharing them.

For CI capture, use a macOS runner with Xcode, an installed simulator runtime, CocoaPods, and the app's dependencies. The repository's existing Linux workflow runs unit tests and type checks; it does not perform iOS captures. Snapbot does not provision runners, schedule jobs, publish artifacts, or implement a baseline comparison service.

On this page