GitHub PR previews
Provision an isolated database branch for every pull request, post a schema safety table, and clean up on close.
Mantis ships a built-in GitHub Actions workflow and CLI commands (ci init, pr-check, and
pr-cleanup) so every pull request gets its own isolated Postgres branch (pr-<number>) and a
live schema safety report before merging to main.
Set up in one command
npx shipmantis ci initThis writes .github/workflows/mantis-preview.yml:
name: Mantis PR Preview & Safety Check
on:
pull_request:
types: [opened, synchronize, reopened, closed]
permissions:
pull-requests: write
jobs:
preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Provision PR branch & check schema safety
env:
MANTIS_URL: ${{ secrets.MANTIS_URL }}
MANTIS_SECRET_KEY: ${{ secrets.MANTIS_SECRET_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: npx -y shipmantis pr-check --comment
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Delete PR preview branch
env:
MANTIS_URL: ${{ secrets.MANTIS_URL }}
MANTIS_SECRET_KEY: ${{ secrets.MANTIS_SECRET_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: npx -y shipmantis pr-cleanupAdd MANTIS_URL and MANTIS_SECRET_KEY (or a scoped branch_only key so CI can never
modify main) to your GitHub repository secrets.
What pr-check does
On every PR open or push (synchronize):
- Creates or resets
pr-<number>frommain(or--from <parent>), giving your PR tests a clean, isolated copy of your schema and data. - Plans your PR's
mantis/schema.tsagainstmainand classifies every step as Safe (auto-applies onmain) or Held (requires human approval onmainbecause it can lose data or widen access). - Applies the migration to
pr-<number>to prove it executes cleanly on Postgres 17. - Upserts one comment on the PR (when
--commentis passed) with the branch name, applied schema version, and step-by-step safety table — updating the same comment on later pushes instead of spamming the thread.
Flags
npx shipmantis pr-check \
[--pr <number>] \
[--schema <file>] \
[--from <parent>] \
[--branch <name>] \
[--comment] \
[--json] \
[--fail-on-destructive]| Flag | What it does |
|---|---|
--pr <number> | Pull request number. Falls back to PR_NUMBER or GITHUB_PR_NUMBER. |
--schema <file> | Schema file path. Default: mantis/schema.ts. |
--from <parent> | Parent branch to clone/plan against. Default: main. |
--branch <name> | Override the preview branch name (default pr-<number>). |
--comment | Create or update the safety report comment on GitHub (requires GITHUB_TOKEN and GITHUB_REPOSITORY). |
--json | Print the structured report as JSON instead of Markdown. |
--fail-on-destructive | Exit with code 2 if any step would be held on main (useful as a required check). |
Automatic cleanup with pr-cleanup
When a pull request is closed or merged, mantis pr-cleanup deletes pr-<number> and its Postgres
database so preview branches never eat into your plan's storage quota. If the branch was already
deleted, pr-cleanup exits cleanly with code 0.
npx shipmantis pr-cleanup --pr 42