Skip to content

Commit 4afbbbe

Browse files
Merge pull request #7 from prisma/feat/run-composer-under-bun
feat: run Composer under Bun for all repos
2 parents bca0702 + 534a7a3 commit 4afbbbe

5 files changed

Lines changed: 88 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
- uses: actions/setup-node@v4
3333
with:
3434
node-version: 22
35+
cache: npm
36+
- uses: oven-sh/setup-bun@v2
3537
- uses: prisma/cloud-deploy-action@v1
3638
with:
3739
build-command: npm run build
@@ -46,6 +48,8 @@ jobs:
4648
- uses: actions/setup-node@v4
4749
with:
4850
node-version: 22
51+
cache: npm
52+
- uses: oven-sh/setup-bun@v2
4953
- uses: prisma/cloud-deploy-action@v1
5054
with:
5155
mode: destroy
@@ -70,7 +74,7 @@ An explicit token always wins over the OIDC exchange.
7074

7175
## How it works
7276

73-
Each run has three phases: install, build, and deploy. Your workflow owns checkout and the toolchain. The action runs your install and build commands exactly as configured, and it never inspects your repository to decide how to build. The deploy phase hands your built app to the [Prisma Composer](https://github.com/prisma/composer) CLI.
77+
Each run has three phases: install, build, and deploy. Your workflow owns checkout and the toolchain. The action runs your install and build commands exactly as configured, and it never inspects your repository to decide how to build. The deploy phase hands your built app to the [Prisma Composer](https://github.com/prisma/composer) CLI, running it under Bun. Bun must be on the runner PATH — add `oven-sh/setup-bun@v2` before this action. The generated Prisma deploy workflow includes that step automatically.
7478

7579
Deploy targets follow your branches:
7680

@@ -89,7 +93,7 @@ The credential resolves in order: an explicit `PRISMA_SERVICE_TOKEN` from the en
8993
| `module` | `module.ts` | Path to your app's Composer module. |
9094
| `mode` | `deploy` | `deploy` or `destroy`. |
9195
| `stage` | derived | Empty derives the stage from the branch: the default branch deploys to production, any other branch name becomes the stage. `destroy` requires a resolved stage. |
92-
| `composer-version` | `0.7.0` | The Composer CLI version the action fetches via npx when the repo has no local bin. From 0.7.0 the bin ships in `@prisma/composer-cli`; set to a `0.6.x` value only if you need the old package. |
96+
| `composer-version` | `0.7.0` | The Composer CLI version the action fetches via bunx when the repo has no local bin. From 0.7.0 the bin ships in `@prisma/composer-cli`; set to a `0.6.x` value only if you need the old package. |
9397
| `working-directory` | `.` | Where install, build, and deploy run. |
9498
| `api-url` | `https://api.prisma.io` | Prisma API base URL for the OIDC credential exchange. |
9599

@@ -110,9 +114,12 @@ On a successful deploy, the action also reports the deployed preview URL (`deplo
110114

111115
When a run has no credential, no `[report-stub]` log lines appear; the run is silent on reporting.
112116

117+
## Requirements
118+
119+
Bun must be on the runner PATH. Add `oven-sh/setup-bun@v2` before this action step. The generated Prisma deploy workflow adds this step for every project.
120+
113121
## Known limitations
114122

115-
- Keep the workflow on Node 22. The Composer CLI has not been verified against Node 24, even though the action itself runs on the runner's Node 24.
116123
- Install detection covers npm and bun lockfiles. Repositories using pnpm or yarn need an explicit `install-command`, and deploys are not tested against them yet.
117124
- Workflow runs triggered from forks receive no OIDC token from GitHub, so they skip deploying unless a `PRISMA_SERVICE_TOKEN` secret is provided.
118125
- The deployed preview URL is read from Composer's human deploy output, because released Composer (0.6.0) does not expose it as data. When Composer emits the deploy result in a machine-readable form — a `--json` result carrying each deployed service's public URL — the action should read the URL from there rather than from the printed report.

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inputs:
1717
description: Empty derives the stage from the branch (default branch deploys to production, any other branch name becomes the stage)
1818
default: ""
1919
composer-version:
20-
description: The @prisma/composer-cli version the action fetches via npx when the repo has no local bin (0.7.0+); use @prisma/composer for 0.6.x
20+
description: The @prisma/composer-cli version the action fetches via bunx when the repo has no local bin (0.7.0+); use @prisma/composer for 0.6.x
2121
default: "0.7.0"
2222
working-directory:
2323
description: Where install, build, and deploy run

‎composer.mjs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Returns [cmd, leadArgs, logLabel] for running the Composer CLI under Bun.
3+
*
4+
* @param {string} localBin - Absolute path to the local prisma-composer binary.
5+
* @param {string} composerVersion - @prisma/composer-cli version to fetch via bunx when the local bin is absent.
6+
* @param {boolean} binExists - Whether the local bin file exists.
7+
* @returns {[string, string[], string]}
8+
*/
9+
export function selectComposerCommand(localBin, composerVersion, binExists) {
10+
if (binExists) {
11+
return ["bun", [localBin], "composer=local bin (bun)"];
12+
}
13+
return [
14+
"bunx",
15+
["--bun", "-p", `@prisma/composer-cli@${composerVersion}`, "prisma-composer"],
16+
`composer=${composerVersion} (bunx fallback)`,
17+
];
18+
}

‎main.mjs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { spawnSync } from "node:child_process";
55
import { appendFileSync, existsSync, readFileSync, writeSync } from "node:fs";
66
import { join, resolve } from "node:path";
7+
import { selectComposerCommand } from "./composer.mjs";
78
import { resolveCredential } from "./credentials.mjs";
89
import { deployedUrlFromOutput } from "./deployment.mjs";
910
import { guardReport, makeReporter, mapPhase } from "./report.mjs";
@@ -136,6 +137,16 @@ if (mode === "destroy" && !stage) {
136137
}
137138
log(stage ? `${mode} target: --stage ${stage}` : `${mode} target: production (default branch, no --stage)`);
138139

140+
// Bun is required: composer runs under Bun, not Node. The generated Prisma
141+
// deploy workflow adds `oven-sh/setup-bun@v2` for every project.
142+
const bunVersionCheck = spawnSync("bun", ["--version"], { stdio: "pipe" });
143+
if (bunVersionCheck.error?.code === "ENOENT") {
144+
failEarly(
145+
"config",
146+
"bun not found on PATH: add `- uses: oven-sh/setup-bun@v2` before this action step; the generated Prisma deploy workflow includes this automatically",
147+
);
148+
}
149+
139150
const installCommand = (() => {
140151
const explicit = input("install-command");
141152
if (explicit) return explicit;
@@ -228,13 +239,15 @@ await runPhase("build", input("build-command") || "npm run build");
228239
// The CLI bin is named prisma-composer. From 0.7.0 it ships inside
229240
// @prisma/composer-cli (previously @prisma/composer); there is no npm package
230241
// named prisma-composer, so `npx prisma-composer@v` 404s. The repo's own
231-
// install already provides the bin, so prefer the local bin; fall back to
232-
// fetching the pinned package only when the repo does not carry it.
242+
// install already provides the bin, so prefer the local bin under Bun; fall
243+
// back to bunx fetching the pinned package when the repo does not carry it.
233244
const localBin = join(workdir, "node_modules", ".bin", "prisma-composer");
234-
const [composerCmd, composerLead] = existsSync(localBin)
235-
? [localBin, []]
236-
: ["npx", [`--package=@prisma/composer-cli@${composerVersion}`, "prisma-composer"]];
237-
log(composerCmd === localBin ? "composer=local bin" : `composer=${composerVersion} (npx fallback)`);
245+
const [composerCmd, composerLead, composerLabel] = selectComposerCommand(
246+
localBin,
247+
composerVersion,
248+
existsSync(localBin),
249+
);
250+
log(composerLabel);
238251
const composerArgs = [
239252
...composerLead,
240253
...(mode === "deploy"

‎tests/composer.test.mjs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import assert from "node:assert/strict";
2+
import { test } from "node:test";
3+
import { selectComposerCommand } from "../composer.mjs";
4+
5+
test("uses bun with the local bin when it exists", () => {
6+
const [cmd, lead, label] = selectComposerCommand(
7+
"/work/node_modules/.bin/prisma-composer",
8+
"0.9.0",
9+
true,
10+
);
11+
assert.equal(cmd, "bun");
12+
assert.deepEqual(lead, ["/work/node_modules/.bin/prisma-composer"]);
13+
assert.equal(label, "composer=local bin (bun)");
14+
});
15+
16+
test("falls back to bunx with --bun when the local bin is absent", () => {
17+
const [cmd, lead, label] = selectComposerCommand(
18+
"/work/node_modules/.bin/prisma-composer",
19+
"0.9.0",
20+
false,
21+
);
22+
assert.equal(cmd, "bunx");
23+
assert.deepEqual(lead, [
24+
"--bun",
25+
"-p",
26+
"@prisma/composer-cli@0.9.0",
27+
"prisma-composer",
28+
]);
29+
assert.equal(label, "composer=0.9.0 (bunx fallback)");
30+
});
31+
32+
test("bunx fallback log label includes the exact version", () => {
33+
const [, , label] = selectComposerCommand("/any", "0.7.5", false);
34+
assert.equal(label, "composer=0.7.5 (bunx fallback)");
35+
});
36+
37+
test("local bin label is always the same string regardless of version", () => {
38+
const [, , label] = selectComposerCommand("/any", "0.7.5", true);
39+
assert.equal(label, "composer=local bin (bun)");
40+
});

0 commit comments

Comments
 (0)