Skip to content

Commit

Permalink
ci(driver adapters): Workflow that runs driver adapters smoke test in…
Browse files Browse the repository at this point in the history
… CI (#4266)
  • Loading branch information
janpio authored Sep 22, 2023
1 parent d96b0d4 commit 571a521
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 36 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/driver-adapter-smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Driver Adapters, Smoke Tests
on:
push:
branches:
- main
pull_request:
paths-ignore:
- '.buildkite/**'
- '*.md'
- 'LICENSE'
- 'CODEOWNERS'
- 'renovate.json'

jobs:
driver-adapter-smoke-tests:
name: Smoke tests for adapter ${{ matrix.adapter }}

strategy:
fail-fast: false
matrix:
adapter: ["neon:ws", "neon:http", planetscale, pg]

runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

env:
JS_NEON_DATABASE_URL: ${{ secrets.JS_NEON_DATABASE_URL }}
JS_PLANETSCALE_DATABASE_URL: ${{ secrets.JS_PLANETSCALE_DATABASE_URL }}
JS_PG_DATABASE_URL: postgres://postgres:postgres@localhost:5432/test # ${{ secrets.JS_PG_DATABASE_URL }}

steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable

- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
#cache: 'pnpm'

- name: Compile Query Engine
run: cargo build -p query-engine-node-api

- name: Install Dependencies (Driver Adapters)
run: pnpm install
working-directory: ./query-engine/driver-adapters/js
- name: Build Driver Adapters
run: pnpm build
working-directory: ./query-engine/driver-adapters/js

- run: pnpm prisma:${{ matrix.adapter }}
working-directory: ./query-engine/driver-adapters/js/smoke-test-js
- run: pnpm ${{ matrix.adapter }}:libquery
working-directory: ./query-engine/driver-adapters/js/smoke-test-js
- name: pnpm ${{ matrix.adapter }}:client (using @prisma/client - including engine! - from Npm)
run: pnpm ${{ matrix.adapter }}:client
if: always()
working-directory: ./query-engine/driver-adapters/js/smoke-test-js

- name: pnpm errors
run: pnpm errors
if: always()
working-directory: ./query-engine/driver-adapters/js/smoke-test-js
30 changes: 15 additions & 15 deletions query-engine/driver-adapters/js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions query-engine/driver-adapters/js/smoke-test-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,40 @@
"prisma:db:push:mysql": "prisma db push --schema ./prisma/mysql/schema.prisma --force-reset",
"prisma:db:execute:mysql": "prisma db execute --schema ./prisma/mysql/schema.prisma --file ./prisma/mysql/commands/type_test/insert.sql",
"prisma:studio:mysql": "prisma studio --schema ./prisma/mysql/schema.prisma",
"prisma:neon:ws": "pnpm prisma:neon",
"prisma:neon:http": "pnpm prisma:neon",
"prisma:neon": "cross-env-shell DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" \"pnpm prisma:db:push:postgres && pnpm prisma:db:execute:postgres\"",
"studio:neon": "cross-env-shell DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" \"pnpm prisma:studio:postgres\"",
"neon:ws:libquery": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --loader=tsx ./src/libquery/neon.ws.test.ts",
"neon:http:libquery": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --loader=tsx ./src/libquery/neon.http.test.ts",
"neon:ws:client": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --loader=tsx ./src/client/neon.ws.test.ts",
"neon:http:client": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --loader=tsx ./src/client/neon.http.test.ts",
"neon:ws:libquery": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/libquery/neon.ws.test.ts",
"neon:http:libquery": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/libquery/neon.http.test.ts",
"neon:ws:client": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/client/neon.ws.test.ts",
"neon:http:client": "DATABASE_URL=\"${JS_NEON_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/client/neon.http.test.ts",
"neon:ws": "pnpm neon:ws:libquery && pnpm neon:ws:client",
"neon:http": "pnpm neon:http:libquery && pnpm neon:http:client",
"prisma:pg": "cross-env-shell DATABASE_URL=\"${JS_PG_DATABASE_URL}\" \"pnpm prisma:db:push:postgres && pnpm prisma:db:execute:postgres\"",
"studio:pg": "cross-env-shell DATABASE_URL=\"${JS_PG_DATABASE_URL}\" \"pnpm prisma:studio:postgres\"",
"pg:libquery": "cross-env-shell DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --loader=tsx ./src/libquery/pg.test.ts",
"pg:client": "DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --loader=tsx ./src/client/pg.test.ts",
"pg:libquery": "cross-env-shell DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/libquery/pg.test.ts",
"pg:client": "DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/client/pg.test.ts",
"pg": "pnpm pg:libquery && pnpm pg:client",
"errors": "DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --loader=tsx ./src/libquery/errors.test.ts",
"errors": "DATABASE_URL=\"${JS_PG_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/libquery/errors.test.ts",
"prisma:planetscale": "cross-env-shell DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" \"pnpm prisma:db:push:mysql && pnpm prisma:db:execute:mysql\"",
"studio:planetscale": "cross-env-shell DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" \"pnpm prisma:studio:mysql\"",
"planetscale:libquery": "DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" node --test --loader=tsx ./src/libquery/planetscale.test.ts",
"planetscale:client": "DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" node --test --loader=tsx ./src/client/planetscale.test.ts",
"planetscale:libquery": "DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/libquery/planetscale.test.ts",
"planetscale:client": "DATABASE_URL=\"${JS_PLANETSCALE_DATABASE_URL}\" node --test --test-reporter spec --loader=tsx ./src/client/planetscale.test.ts",
"planetscale": "pnpm planetscale:libquery && pnpm planetscale:client"
},
"keywords": [],
"author": "Alberto Schiabel <[email protected]>",
"license": "Apache-2.0",
"sideEffects": true,
"dependencies": {
"@neondatabase/serverless": "^0.6.0",
"@planetscale/database": "^1.11.0",
"@prisma/adapter-neon": "workspace:*",
"@prisma/adapter-planetscale": "workspace:*",
"@prisma/adapter-pg": "workspace:*",
"@prisma/adapter-planetscale": "workspace:*",
"@prisma/client": "5.4.0-dev.29",
"@prisma/driver-adapter-utils": "workspace:*",
"@neondatabase/serverless": "^0.6.0",
"@planetscale/database": "^1.11.0",
"@prisma/client": "5.3.0-integration-feat-driver-adapters-in-client.3",
"pg": "^8.11.3",
"superjson": "^1.13.1",
"undici": "^5.23.0"
Expand All @@ -51,7 +53,7 @@
"@types/node": "^20.5.1",
"@types/pg": "^8.10.2",
"cross-env": "^7.0.3",
"prisma": "5.3.0-integration-feat-driver-adapters-in-client.3",
"prisma": "5.4.0-dev.29",
"tsx": "^3.12.7"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, it } from 'node:test'
import path from 'node:path'
import assert from 'node:assert'
import { PrismaClient } from '@prisma/client'
import type { DriverAdapter } from '@prisma/driver-adapter-utils'
import { getLibQueryEnginePath } from '../libquery/util'

export async function smokeTestClient(driverAdapter: DriverAdapter) {
const provider = driverAdapter.flavour
Expand All @@ -13,6 +15,9 @@ export async function smokeTestClient(driverAdapter: DriverAdapter) {
} as const,
]

const dirname = path.dirname(new URL(import.meta.url).pathname)
process.env.PRISMA_QUERY_ENGINE_LIBRARY = getLibQueryEnginePath(dirname)

for (const adapter of [driverAdapter, undefined]) {
const isUsingDriverAdapters = adapter !== undefined
describe(isUsingDriverAdapters ? `using Driver Adapters` : `using Rust drivers`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { smokeTestClient } from './client'
describe('neon with @prisma/client', async () => {
const connectionString = process.env.JS_NEON_DATABASE_URL ?? ''

const connection = neon(connectionString, {
arrayMode: false,
fullResults: true,
})
const connection = neon(connectionString)
const adapter = new PrismaNeonHTTP(connection)

smokeTestClient(adapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ export function initQueryEngine(
driver: ErrorCapturingDriverAdapter,
prismaSchemaRelativePath: string,
): QueryEngineInstance {
// I assume nobody will run this on Windows ¯\_(ツ)_/¯
const libExt = os.platform() === 'darwin' ? 'dylib' : 'so'
const dirname = path.dirname(new URL(import.meta.url).pathname)
const libQueryEnginePath = getLibQueryEnginePath(dirname)

const libQueryEnginePath = path.join(dirname, `../../../../../../target/debug/libquery_engine.${libExt}`)
const schemaPath = path.join(dirname, prismaSchemaRelativePath)

console.log('[nodejs] read Prisma schema from', schemaPath)
Expand Down Expand Up @@ -43,6 +41,12 @@ export function initQueryEngine(
return engine
}

export function getLibQueryEnginePath(dirname: String) {
// I assume nobody will run this on Windows ¯\_(ツ)_/¯
const libExt = os.platform() === 'darwin' ? 'dylib' : 'so'
return path.join(dirname, `../../../../../../target/debug/libquery_engine.${libExt}`)
}

export function createQueryFn(engine: QueryEngineInstance, adapter: ErrorCapturingDriverAdapter) {
return async function doQuery(query: JsonQuery, tx_id?: string) {
const result = await engine.query(JSON.stringify(query), 'trace', tx_id)
Expand Down

0 comments on commit 571a521

Please sign in to comment.