Skip to content

Instantly share code, notes, and snippets.

@2color
Last active April 10, 2024 18:57
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 2color/537f8ef13ecec80059abb007839a6878 to your computer and use it in GitHub Desktop.
Save 2color/537f8ef13ecec80059abb007839a6878 to your computer and use it in GitHub Desktop.
How to run integration tests with PostgreSQL and Prisma on GitHub Actions
# .github/workflows/test.yaml
name: test
on: push
jobs:
test:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub PostgreSQL image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/fastify-graphql
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
- run: npm ci
- run: npm run build
# Create the database
- run: npx prisma migrate deploy
- run: npm run test
@phultquist
Copy link

Why is the name of the database fastify-graphql?

@2color
Copy link
Author

2color commented Feb 14, 2023

Prisma Migrate will create it but it can be anything

@shadeemerhi
Copy link

This works great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment