Using Ghostrow in CI
Run Ghostrow in a pipeline: fixed seeds, quiet and JSON output, exit codes, Max CI tokens with GHOSTROW_CI_TOKEN, and a GitHub Actions example.
Ghostrow suits CI: it needs no interactive input, it works from a schema file, and the same inputs give the same rows.
Make runs repeatable
- Commit your schema (or ORM models) and
ghostrow.rules.yaml. - Pass
--seedand--rowsexplicitly. - Pin the Ghostrow version you install, so an upgrade changes your data on purpose, not by surprise. For npm, use
npm i -g ghostrow@<version>. The install scripts readGHOSTROW_VERSION. - Leave
GHOSTROW_AI_PROVIDERunset, or commit the labels it chose.
ghostrow seed --schema schema.sql --rows 2000 --seed 42 --format sql --out fixtures/
Output for scripts
| Option | Effect |
|---|---|
--json | One JSON document on stdout. Progress and notices go to stderr |
-q, --quiet | No normal output on success. Errors, and notices that change what the run does, are still printed to stderr |
| both | --json wins: the document is still printed |
Since 1.0.1, a notice such as GHOSTROW_CI_TOKEN was not accepted ..., which explains why a run fell back to Free limits, is printed to stderr even with --quiet.
Exit codes
A pipeline step fails on any non-zero code.
| Code | Meaning |
|---|---|
0 | Success |
1 | Invalid input or configuration |
2 | A rule could not be satisfied |
3 | haunt --tests found tests that fail only with edge cases |
4 | License problem, or a Free limit was reached |
See Troubleshooting for the messages.
CI tokens (Max)
CI runners are not machines, so they do not need ghostrow activate. On a Max license, the owner creates a CI token on the license page of the account and stores it as a secret. Set it as GHOSTROW_CI_TOKEN in the job.
- On each run, Ghostrow sends the token to ghostrow.com and receives the signed license back. Only that license check goes over the network. Your schema, rules and data do not.
- Without a connection, with a revoked token, or with a wrong one, Ghostrow prints
note: GHOSTROW_CI_TOKEN was not accepted (<reason>). Running at Free limits.and continues on Free. Ahauntstep then fails with exit code 4. - The usual updates rule applies: if your license's updates ended before the release date of the installed version, it runs at Free limits. Pin an older version or renew updates.
Do not run ghostrow activate in CI. That registers the runner as a machine, which a CI token avoids.
GitHub Actions example
Seed from the schema file, then run the tests. This works on Free for schemas up to 5 tables:
name: tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm i -g ghostrow@1.0.0
- run: ghostrow seed --schema db/schema.sql --rows 2000 --seed 42 --format sql --out fixtures/
- run: npm test
Add Haunt with a Max CI token:
- name: Edge cases
env:
GHOSTROW_CI_TOKEN: ${{ secrets.GHOSTROW_CI_TOKEN }}
run: ghostrow haunt --schema db/schema.sql --tests "npm test" --cases 300 --seed 42 --report haunt-report.json
- name: Keep the report
if: failure()
uses: actions/upload-artifact@v4
with:
name: haunt-report
path: haunt-report*.json
Your tests read the edge-case CSV files from the folder in GHOSTROW_HAUNT_DIR. Exit code 3 fails the step when a test breaks only with edge-case data, and the uploaded report names the cases and columns. haunt --tests also runs your test command more than once (the baseline, all cases, then narrowing runs, up to 40 more). Allow for that in the job's time limit.
If your tests use a database, load the files into it first. For haunt --db, point it at the CI database; the rows are inserted and removed again around each test run.