Skip to content
Merged
3 changes: 3 additions & 0 deletions .github/workflows/test-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ jobs:

- run: pnpm tsc -p tsconfig.utils.typecheck.json

- name: Test publish channel selection
run: pnpm tsx --test scripts/ci/publish-channel.test.ts

#
# INTEGRATION-TESTS
#
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **Key packages**: `packages/cli` (Prisma CLI entry point), `packages/migrate` (migrate/db namespace + fixtures), `packages/client` (client runtime), `packages/client-generator-ts` (new `prisma-client` generator), `packages/client-generator-js` (traditional `prisma-client-js` generator), `packages/client-generator-registry` (generator registry for managing generators), `packages/client-engine-runtime` (the core part of the new Rust binary free client based on Wasm query compiler, used by `ClientEngine` class in `packages/client`), `packages/client-common` (shared client utilities), `packages/client-runtime-utils` (utility types and singletons for Prisma Client), `packages/config` (`PrismaConfigInternal` + loader), `packages/internals` (shared CLI + engine glue), `packages/engines` (Rust binaries download wrapper), `packages/integration-tests` (matrix suites), `packages/query-plan-executor` (standalone query plan executor service for Prisma Accelerate), `packages/credentials-store` (credential storage utilities), sqlcommenter packages under `packages/sqlcommenter*`, and numerous driver adapters under `packages/adapter-*`.
- **Driver adapters & runtimes**: `packages/bundled-js-drivers` plus the `adapter-*` packages ship JS driver adapters: `adapter-pg`, `adapter-neon`, `adapter-libsql`, `adapter-planetscale`, `adapter-d1`, `adapter-better-sqlite3`, `adapter-mssql`, `adapter-mariadb`, `adapter-ppg` (Prisma Postgres Serverless). These are built on helpers in `driver-adapter-utils`; migrate/client fixtures exercise them, so adapter changes typically require fixture/test updates. CI tests driver adapters with flavors: `js_pg`, `js_neon`, `js_libsql`, `js_planetscale`, `js_d1`, `js_better_sqlite3`, `js_mssql`, `js_mariadb`, `js_pg_cockroachdb`.
- **Build & tooling**: Typescript-first repo with WASM/Rust assets (downloaded by `@prisma/engines`). Multiple `tsconfig.*` drive bundle vs runtime builds. Lint via `pnpm lint`, format via `pnpm format`. Maintenance scripts live in `scripts/` (e.g. `bump-engines.ts`, `bench.ts`, `ci/publish.ts` orchestrates build/test/publish flows). Build configuration uses esbuild via `helpers/compile/build.ts` with configs in `helpers/compile/configs.ts`. Most packages use `bundledConfig` which bundles to both CJS and ESM with type declarations.
- **npm dist-tags on this branch.** Two publishers share the npm package `prisma`: prisma/prisma-cli (Prisma 8) owns its `latest`, `dev` and `next` tags, and this branch owns `prev`, `prev-dev`, `patch-dev` and `integration`. Stable releases put `prisma` on `prev` and the `@prisma/*` packages on `latest`, so for `@prisma/*` the `prev-dev` tag means "Prisma 7 dev build", not "dev line of `prev`". Every push to `v7` publishes all packages as `<next minor after the highest stable 7.x.y of prisma>-dev.N` under `prev-dev`. Tag and base-version selection live in `scripts/ci/publish-channel.ts`; `getPackageDistTag` there refuses to publish `prisma` under a tag prisma/prisma-cli owns. Its test runs in the `Workspace types` CI job (`pnpm tsx --test scripts/ci/publish-channel.test.ts`). Revisit these tag names when Prisma 9 ships and 8.x needs `prev`.
- Build helpers that copy Wasm artifacts should resolve package assets through `require.resolve(...)` instead of hardcoding `packages/*/node_modules` paths. With pnpm hoisted installs, dependencies can live only at workspace root and package-local `node_modules/@prisma/*` entries may be absent.
- **Benchmarking**: Comprehensive performance benchmarks using Benchmark.js with CodSpeed integration. See `docs/benchmarking.md` for full documentation. Key commands:
- `pnpm bench` - Run all benchmarks (outputs to `output.txt`)
Expand Down
118 changes: 118 additions & 0 deletions scripts/ci/publish-channel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* eslint-disable @typescript-eslint/no-floating-promises -- node:test tracks the promises that describe() and test() return */

import assert from 'node:assert/strict'
import { describe, test } from 'node:test'

import {
getNextMinorStable,
getPackageDistTag,
getPublishChannel,
parseCustomDistTag,
type PublishChannel,
type PublishChannelInput,
} from './publish-channel'

const push: PublishChannelInput = {
branch: 'v7',
patchBranch: null,
releaseVersion: undefined,
forceIntegrationRelease: false,
}

describe('getPublishChannel', () => {
const cases: [string, PublishChannelInput, PublishChannel][] = [
['push to v7', push, { kind: 'dev', tag: 'prev-dev' }],
[
'--release on v7',
{ ...push, releaseVersion: '7.11.0' },
{ kind: 'release', tag: 'latest', ecosystemTestsBranch: 'dev' },
],
[
'push to a patch branch',
{ ...push, branch: '7.9.x', patchBranch: '7.9.x' },
{ kind: 'patch-dev', tag: 'patch-dev' },
],
[
'--release on a patch branch',
{ ...push, branch: '7.9.x', patchBranch: '7.9.x', releaseVersion: '7.9.2' },
{ kind: 'release', tag: 'latest', ecosystemTestsBranch: 'patch-dev' },
],
['push to integration/*', { ...push, branch: 'integration/foo' }, { kind: 'integration', tag: 'integration' }],
[
'forced integration release wins over --release',
{ ...push, forceIntegrationRelease: true, releaseVersion: '7.11.0' },
{ kind: 'integration', tag: 'integration' },
],
]

for (const [name, input, expected] of cases) {
test(name, () => {
assert.deepEqual(getPublishChannel(input), expected)
})
}
})

describe('getPackageDistTag', () => {
const cases: [string, string, string][] = [
['prisma', 'prev-dev', 'prev-dev'],
['@prisma/client', 'prev-dev', 'prev-dev'],
['prisma', 'latest', 'prev'],
['@prisma/client', 'latest', 'latest'],
['prisma', 'patch-dev', 'patch-dev'],
['prisma', 'integration', 'integration'],
['prisma', 'my-custom-tag', 'my-custom-tag'],
['@prisma/client', 'dev', 'dev'],
]

for (const [pkgName, tag, expected] of cases) {
test(`${pkgName} on ${tag} publishes under ${expected}`, () => {
assert.equal(getPackageDistTag(pkgName, tag), expected)
})
}

for (const tag of ['dev', 'next']) {
test(`refuses to publish prisma under ${tag}`, () => {
assert.throws(() => getPackageDistTag('prisma', tag), /prisma\/prisma-cli owns it.*"prev-dev"/)
})
}
})

describe('parseCustomDistTag', () => {
test('removes the whitespace a shell would drop', () => {
assert.equal(parseCustomDistTag(' next'), 'next')
assert.equal(parseCustomDistTag('dev '), 'dev')
})

test('a padded prisma-cli tag is still refused for prisma', () => {
assert.throws(() => getPackageDistTag('prisma', parseCustomDistTag(' dev ')), /prisma\/prisma-cli owns it/)
})

for (const input of ['', 'my tag', 'Dev', 'dev;next', '--tag']) {
test(`refuses ${JSON.stringify(input)}`, () => {
assert.throws(() => parseCustomDistTag(input), /not a usable npm dist-tag/)
})
}
})

describe('getNextMinorStable', () => {
test('returns the next minor after the highest stable 7.x version', () => {
assert.equal(getNextMinorStable(['7.9.0', '7.10.0', '7.10.1', '7.10.0-dev.58']), '7.11.0')
})

test('uses the highest version, not the newest one in the list', () => {
assert.equal(getNextMinorStable(['7.10.1', '7.9.2']), '7.11.0')
})

test('ignores other majors and prereleases', () => {
assert.equal(
getNextMinorStable(['6.19.3', '7.10.1', '7.11.0-dev.1', '7.12.0-integration-foo.1', '8.0.0', '8.0.0-rc.34']),
'7.11.0',
)
})

test('throws when no stable 7.x version exists', () => {
for (const versions of [[], ['6.19.3', '8.0.0', '7.11.0-dev.1', '7.10']]) {
assert.throws(() => getNextMinorStable(versions), /no stable 7\.x\.y version of prisma/)
}
})
})
91 changes: 91 additions & 0 deletions scripts/ci/publish-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Two publishers share the npm package `prisma`. prisma/prisma-cli (Prisma 8) owns its `latest`, `dev` and `next`
* tags. This branch (Prisma 7) owns `prev`, `prev-dev`, `patch-dev` and `integration`.
*
* The `@prisma/*` packages still get stable releases on `latest` from this branch, so for them `prev-dev` means
* "Prisma 7 dev build", not "dev line of `prev`". Revisit these names when Prisma 9 ships and 8.x needs `prev`.
*/
export const DEV_DIST_TAG = 'prev-dev'

export const PRISMA_STABLE_DIST_TAG = 'prev'

const PRISMA_MAJOR = 7

const PRISMA_CLI_OWNED_DIST_TAGS: ReadonlySet<string> = new Set(['latest', 'dev', 'next'])

export type PublishChannelInput = {
branch: string | undefined
patchBranch: string | null
releaseVersion: string | undefined
forceIntegrationRelease: boolean
}

export type PublishChannel = {
kind: 'integration' | 'patch-dev' | 'release' | 'dev'
tag: string
ecosystemTestsBranch?: string
}

export function getPublishChannel({
branch,
patchBranch,
releaseVersion,
forceIntegrationRelease,
}: PublishChannelInput): PublishChannel {
if (branch && (forceIntegrationRelease || branch.startsWith('integration/'))) {
return { kind: 'integration', tag: 'integration' }
}
if (patchBranch) {
return releaseVersion
? { kind: 'release', tag: 'latest', ecosystemTestsBranch: 'patch-dev' }
: { kind: 'patch-dev', tag: 'patch-dev' }
}
if (releaseVersion) {
return { kind: 'release', tag: 'latest', ecosystemTestsBranch: 'dev' }
}
return { kind: 'dev', tag: DEV_DIST_TAG }
}

/**
* Returns the npm dist-tag to publish `pkgName` under. Every publish goes through this, including a custom dist tag.
* Throws if `prisma` would land on a tag prisma/prisma-cli owns.
*/
export function getPackageDistTag(pkgName: string, tag: string): string {
if (pkgName !== 'prisma') return tag
if (tag === 'latest') return PRISMA_STABLE_DIST_TAG
if (PRISMA_CLI_OWNED_DIST_TAGS.has(tag)) {
throw new Error(
`Refusing to publish prisma under the "${tag}" dist-tag: prisma/prisma-cli owns it for Prisma 8. Prisma 7 dev builds use "${DEV_DIST_TAG}".`,
)
}
return tag
}

/**
* Returns a custom dist-tag as npm will receive it. The tag reaches `pnpm publish --tag` through a shell, which drops
* surrounding whitespace, so ` dev` would pass a comparison with `dev` and still publish under it.
*/
export function parseCustomDistTag(input: string): string {
const tag = input.trim()
if (!/^[a-z][a-z0-9._-]*$/.test(tag)) {
throw new Error(`"${input}" is not a usable npm dist-tag: use lowercase letters, digits, ".", "_" and "-".`)
}
return tag
}

/**
* Returns the next minor after the highest stable Prisma 7 version in `publishedVersions`, e.g. `7.10.1` -> `7.11.0`.
* Reads the version list rather than a dist-tag, because a release from an older patch branch moves `prev` back.
*/
export function getNextMinorStable(publishedVersions: readonly string[]): string {
const minors = publishedVersions.flatMap((version) => {
const match = /^(\d+)\.(\d+)\.\d+$/.exec(version.trim())
return match && Number(match[1]) === PRISMA_MAJOR ? [Number(match[2])] : []
})
if (minors.length === 0) {
throw new Error(
`Found no stable ${PRISMA_MAJOR}.x.y version of prisma on npm. Dev and integration versions are based on the highest one.`,
)
}
return `${PRISMA_MAJOR}.${Math.max(...minors) + 1}.0`
}
Loading
Loading