Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/product/command-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The long-term command surface grows through workflow groups such as:
- `db`
- `app`
- `git`
- `build`

The preview implements only `auth`, `project`, `git`, `branch`, `database`, `bucket`, `app`, `skills`, and `init`.

Expand All @@ -53,6 +54,7 @@ The CLI should keep the meaning of these nouns stable:
- `service`
- `version` (always qualified in prose: a service version)
- `domain`
- `build` (one run that built and deployed the app from a Git commit, such as a GitHub Actions run of the deploy workflow; its id starts with `bld_`)

If a noun means one thing in docs and a different thing in commands or output, the model is already drifting.

Expand Down Expand Up @@ -128,7 +130,7 @@ The scaffolded config imports `definePrismaConfig` from `prisma/config` and spel

### `logs`

Resolve a service version and show or stream its logs.
Show the logs of one resource. `service logs` resolves a service version and shows or streams what it printed while running. `build logs` shows the CI job log of one build, the newest one when no build id is given. Build logs are a separate group because a build is not owned by one service: one build can deploy several.

### `delete` and `remove`

Expand Down
15 changes: 15 additions & 0 deletions docs/reference/error-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Namespaces:
| `AUTH` | Workspace authentication and sessions (`prisma auth`, credential resolution) |
| `BRANCH` | Branch listing (`prisma branch`) |
| `BUCKET` | Bucket and bucket-key management (`prisma bucket`) |
| `BUILD` | Listing builds and reading a build's log (`prisma build`) |
| `CLI` | Engine-level invocation: arguments, config loading, prompts, consent, credentials, child processes |
| `CONFIG` | The `composer` section of `prisma.config.ts` and its `config` and `secrets` adapters (`prisma dev`, `prisma deploy`) |
| `DEPLOY` | Deploying, listing and destroying a Composer app (`prisma deploy`, `prisma deploy list`, and the `deploy` and `destroy` operations of `@prisma/composer/control`), and building the one Service of a repository with no Composer config (`prisma deploy`), whose codes start with `DEPLOY.SERVICE_` |
Expand Down Expand Up @@ -120,6 +121,20 @@ A bucket Management API request (listing, creating, or deleting buckets or bucke

A bucket subcommand was called without its required id argument: `bucket delete` and `bucket key create`/`bucket key list` need a bucket id, and `bucket key delete` needs both a bucket id and a key id. The nextActions point at `bucket list` (or `bucket key list`) to find the ids. Meta: none.

## BUILD

### BUILD.API_ERROR

A Management API request made by `prisma build list` or `prisma build logs` failed. The `why` carries the API's message or, failing that, the HTTP status. For `build logs` the message says what to do: a build that did not run in GitHub Actions has no log here, a GitHub rate limit says how long to wait (HTTP 503), and a missing GitHub App permission links to where to approve it. For an unknown build id (HTTP 404), the next action is `prisma build list`. Meta: `status`, `apiCode` (the API's own error code, when the response supplied one).

### BUILD.NONE

`prisma build logs` was run without a build id, and the project has no builds yet. A build is reported when the deploy workflow runs on a push, or when `prisma deploy` runs. Meta: none.

### BUILD.USAGE_ERROR

`prisma build logs` was given a `--tail` that is not a whole number from 1 to 1000. Leave `--tail` out to print every line. Meta: none.

## CLI

### CLI.ABORTED
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@prisma/management-api-sdk": "^1.55.0"
},
"devDependencies": {
"@prisma/management-api-sdk": "1.101.0",
"@prisma/management-api-sdk": "1.110.0",
"@repo/cli-conformance": "workspace:8.0.0-rc.39",
"@repo/tsconfig": "workspace:8.0.0-rc.39",
"@types/node": "^22.19.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Architecture and contributor workflow references:
- Group commands by developer workflow, not product ownership.
- No `orm`, `postgres`, or `compute` namespaces in the command surface.
- Canonical command shape is `prisma <group> <action>`.
- The shipped groups are `auth`, `project`, `git`, `branch`, `postgres`, `bucket`, `service`, `skills`, the root `init` and `deploy` verbs, `dev` (a command that is also a group: `dev url`, `dev stop`), `emulator`, and the ORM family (`contract`, `db`, `migration`, `orm init`, `lsp`).
- The shipped groups are `auth`, `project`, `git`, `branch`, `postgres`, `bucket`, `service`, `build`, `skills`, the root `init` and `deploy` verbs, `dev` (a command that is also a group: `dev url`, `dev stop`), `emulator`, and the ORM family (`contract`, `db`, `migration`, `orm init`, `lsp`).
- Preserve the long-term resource model: `workspace -> project -> branch -> { service, database, bucket }`.

The mounted tree in `packages/cli/src/cli.ts` is the authoritative command surface.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This package exposes `prisma-cli` so it can coexist with the existing
| `postgres` | Create, inspect, back up, restore, and delete Prisma Postgres databases and their connections. |
| `bucket` | Create, list, and delete object-store buckets and their access keys. |
| `service` | Inspect services: versions, logs, domains, promote, roll back, delete. |
| `build` | List the runs that built and deployed your app, and print one build's log from GitHub Actions. |
| `dev`, `deploy` | Run a Composer app locally; deploy it to the platform. `dev url` prints a running node's local URL and `dev stop` stops the app. In a repository with no Composer config, `deploy` deploys the folder as one Service, built from its own install, build and start commands. |
| `emulator` | List the local emulators `prisma dev` runs services, databases and buckets on. |
| `contract`, `db`, `migration`, `orm init`, `lsp` | The Prisma ORM workflow. |
Expand Down
71 changes: 71 additions & 0 deletions packages/cli/e2e/build.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/** Real-API runs of the build commands, on a build this file reports. */
import { beforeAll, expect, it } from "vitest";

import { apiBaseUrl, serviceToken } from "./deployed-service";
import { useScratchProject } from "./scratch";
import { describeCommand } from "./suite";

const scratch = useScratchProject("build");

let buildId: string;

/** Reports a build the way `prisma deploy` does from a laptop. Only a
* GitHub Actions run can report a build that has a log, and this suite
* has none, so `build logs` is checked on the answer for this build. */
beforeAll(async () => {
const response = await fetch(`${apiBaseUrl()}/v1/builds`, {
method: "POST",
headers: {
authorization: `Bearer ${serviceToken()}`,
"content-type": "application/json",
},
body: JSON.stringify({
source: "cli",
commitSha: "0123456789abcdef0123456789abcdef01234567",
branchName: "main",
projectId: scratch.project().id,
}),
});
if (!response.ok) {
throw new Error(
`could not report a build: HTTP ${response.status} ${await response.text()}`,
);
}
buildId = ((await response.json()) as { data: { id: string } }).data.id;
});

describeCommand("build list", () => {
it("lists the project's builds, including one just reported", async () => {
const run = await scratch.run(["build", "list"]);
const result = run.envelope.result as {
readonly projectId: string;
readonly builds: ReadonlyArray<{
readonly id: string;
readonly state: string;
readonly branchName: string;
}>;
};

expect(run.exitCode).toBe(0);
expect(result.projectId).toBe(scratch.project().id);
expect(result.builds).toContainEqual(
expect.objectContaining({
id: buildId,
state: "pending",
branchName: "main",
}),
);
});
});

describeCommand("build logs", () => {
it("reads the newest build, and says one that did not run in GitHub Actions has no log", async () => {
const run = await scratch.run(["build", "logs"], { expectOk: false });

expect(run.envelope.ok).toBe(false);
expect(run.envelope.error?.code).toBe("BUILD.API_ERROR");
expect(run.envelope.error?.why).toContain(
"was not reported by a GitHub Actions run",
);
});
});
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@prisma/composer-cli": "0.41.2",
"@prisma/composer-prisma-cloud": "0.41.2",
"@prisma/compute-sdk": "0.47.0",
"@prisma/management-api-sdk": "1.101.0",
"@prisma/management-api-sdk": "1.110.0",
"@prisma/orm-family-sql": "8.0.0-rc.28",
"@prisma/orm-framework": "8.0.0-rc.28",
"@prisma/orm-postgres": "8.0.0-rc.28",
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { bucketKeyCreateCommand } from "./commands/bucket/key-create";
import { bucketKeyDeleteCommand } from "./commands/bucket/key-delete";
import { bucketKeyListCommand } from "./commands/bucket/key-list";
import { bucketListCommand } from "./commands/bucket/list";
import { buildListCommand } from "./commands/build/list";
import { buildLogsCommand } from "./commands/build/logs";
import { createDeployCommand } from "./commands/deploy/command";
import {
deployConfigSection,
Expand Down Expand Up @@ -118,6 +120,8 @@ export const platformCommandFamily: CommandFamily = defineCommandFamily({
bucketKeyCreate: bucketKeyCreateCommand,
bucketKeyDelete: bucketKeyDeleteCommand,
branchList: branchListCommand,
buildList: buildListCommand,
buildLogs: buildLogsCommand,
gitConnect: gitConnectCommand,
gitDisconnect: gitDisconnectCommand,
serviceList: serviceListCommand,
Expand Down Expand Up @@ -289,6 +293,22 @@ export const cliGroups: Readonly<
description:
"A Branch maps to a Git branch of the connected repository. Each is an isolated environment with its own services, databases, buckets, and environment variables: the production branch serves live traffic, every other branch is a preview.",
},
build: {
brief:
"Inspect the runs that build and deploy your app. List recent builds, print one build's log",
description:
"A build is one run that built and deployed your app from a Git commit: a GitHub Actions run of the deploy workflow on push, or a 'prisma deploy' from your machine. Each has an id (bld_...) and a state: pending, running, succeeded, failed, or cancelled. 'logs' reads a build's log from GitHub Actions, so it works only for builds that ran there.",
workflow: [
{
run: "build list --state failed",
brief: "Find the builds that failed, newest first",
},
{
run: "build logs --errors",
brief: "Print the error lines of the newest build",
},
],
},
git: {
brief:
"Manage the GitHub connection behind deploy-on-push. Connect or disconnect a repository",
Expand Down Expand Up @@ -437,6 +457,8 @@ export const mountedCommands: Readonly<Record<string, AnyCommand>> = {
"bucket key create": bucketKeyCreateCommand,
"bucket key delete": bucketKeyDeleteCommand,
"branch list": branchListCommand,
"build list": buildListCommand,
"build logs": buildLogsCommand,
"git connect": gitConnectCommand,
"git disconnect": gitDisconnectCommand,
"service list": serviceListCommand,
Expand Down
43 changes: 43 additions & 0 deletions packages/cli/src/commands/build/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CliStructuredError } from "@prisma/cli-engine/protocol";
import { CLI_NAME } from "../../cli-name";
import {
type ApiErrorBody,
apiErrorDetail,
} from "../../lib/management-api-error";

/** The API's message is the `why`: for a build log it already says what
* to do. Its hint is not used, because it names API routes, not commands. */
export function buildApiError(
summary: string,
response: Response | undefined,
error: ApiErrorBody | undefined,
): CliStructuredError {
const status = response?.status ?? 0;
const detail = apiErrorDetail(error);
return new CliStructuredError("BUILD.API_ERROR", summary, {
why:
detail.message ??
`The Management API returned status ${status || "unknown"}.`,
...(status || detail.code !== undefined
? {
meta: {
...(status ? { status } : {}),
...(detail.code !== undefined ? { apiCode: detail.code } : {}),
},
}
: {}),
nextActions: [
status === 404
? {
kind: "run-command",
label: "List the project's builds",
command: `${CLI_NAME} build list`,
}
: {
kind: "user-choice",
label:
"Re-run with --log-level verbose for the underlying API response details.",
},
],
});
}
Loading
Loading