DocsRecipes
GitHub Actions
Drop-in workflow for seeding a test database on every PR — cache hit means no LLM cost.
The canonical CI pattern. Cache hit is fast and free; cache miss regenerates and stores under your seed name so subsequent runs hit.
Workflow
name: Test
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testdb
ports: ['5432:5432']
options: >-
--health-cmd pg_isready --health-interval 10s
--health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm ci
- name: Apply migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
- name: Seed test database
run: |
npx seedkit-cli seed \
--url $DATABASE_URL \
--schema prisma/schema.prisma \
--seed test-fixture --from-cache --reset
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
SEEDKIT_TOKEN: ${{ secrets.SEEDKIT_TOKEN }}
- run: npm test
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
What's happening
- A Postgres service container starts.
- Migrations run (Prisma here; swap for whatever you use).
seedkit seed --from-cachepopulates the DB from your cachedtest-fixtureseed.--resettruncates first so each run starts clean.--from-cachemakes a missing cache an error (instead of silently regenerating in CI).- Your test suite runs.
Setting up the seed first
Before this workflow can hit the cache, you need to lock the seed once locally:
npx seedkit-cli new --schema prisma/schema.prisma --seed test-fixture
That populates the cache. Subsequent CI runs replay from it.
Token
Create a token at app.seedkit.dev/tokens, set it as SEEDKIT_TOKEN in your repo's Actions secrets.
Cache miss in CI
If your schema changes (e.g. a new column lands on main), the cache key changes. With --from-cache set, the next CI run will exit 6 — surfaced as a CI failure. The fix:
# locally:
npx seedkit-cli new --schema prisma/schema.prisma --seed test-fixture --reset
git add . && git commit -m "regenerate test fixture for new schema"
This makes "fixture is out of date" a tracked event, not a silent regeneration.