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
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,39 @@ jobs:
run: bun scripts/sweep.ts

e2e-single-app:
name: The action deploys a repository with no Composer module
name: The action deploys a repository with no Composer module, ${{ matrix.name }}
if: >-
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- name: and no config file
app: single-app
id: plain
# The action installs first, then runs the app's own prisma from its lockfile.
- name: with a prisma.config.ts
app: single-app-config
id: config
permissions:
contents: read
# The sweep reads whether the run that made a Project has finished.
actions: read
env:
# The action cannot destroy a deploy with no Composer module, so each run
# deploys into a Project of its own and deletes that Project afterwards.
PROJECT: cloud-deploy-action-e2e-single-${{ github.run_id }}-${{ github.run_attempt }}
PROJECT: cloud-deploy-action-e2e-single-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.id }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
# No Bun: the action runs the CLI under Node.js in this mode.
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- name: Give the app a body only this run has
run: printf '{"project":"%s"}' "$PROJECT" > e2e/single-app/run.json
run: printf '{"project":"%s"}' "$PROJECT" > "e2e/${{ matrix.app }}/run.json"
# No environment input: a pull request run deploys to an environment named
# after its branch, and a run on main deploys to production.
- name: Deploy with the action
Expand All @@ -191,7 +202,7 @@ jobs:
# The deploy creates the Project, which needs a region. Same as e2e/app.
PRISMA_REGION: us-east-1
with:
working-directory: e2e/single-app
working-directory: e2e/${{ matrix.app }}
name: ${{ env.PROJECT }}
- name: Check the action's outputs and the deployed service
env:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ npx --yes prisma@latest deploy --name <name> --environment <environment>

The Prisma CLI does the rest. It works out how to build and start the Service, builds it, and hands the result to Composer. Composer deploys it as it deploys a Composer module.

- The action runs no install and no build of its own. The `install-command` and `build-command` inputs are not used.
- The action runs no install and no build of its own, and does not use the `install-command` and `build-command` inputs. A repository with a `prisma.config.ts` is the one exception, described below.
- The `prisma-version` input sets the CLI version. Set it to an exact version. Empty runs the newest release and logs a warning, because no lockfile pins the CLI in this mode.
- **A repository with a `prisma.config.ts` is installed first.** The CLI reads that file before it runs, and the file imports the repository's own packages. So the action runs the install command (`install-command`, else from the lockfile: npm, bun, pnpm or yarn), and the CLI then installs again as part of its build. A detected install runs in the nearest folder that has a lockfile, from the working directory up to the repository root, because the CLI also reads a config file above the working directory. The `install-command` input runs in the working directory. When the install gives the repository its own `prisma` at 8.0.0-rc.37 or later and `prisma-version` is empty, the action runs that CLI (`npx --no-install prisma deploy`), because a config file must be read by the CLI from the same install.
- A `prisma.config.ts` written for Prisma ORM 7 stops the deploy with `CLI.CONFIG_MISSING_MARKER`. The CLI refuses a config file that was not made with `definePrismaConfig`.
- A push to the default branch deploys to production, with no `--environment` argument.
- The Service deploys into the Project that has its name. The `name` input sets that name. Empty uses the `name` in `package.json`, else the folder name.
- The first deploy creates the Project when no Project has that name. It then needs a region in the `PRISMA_REGION` environment variable of the step.
Expand Down Expand Up @@ -211,7 +213,7 @@ Branch names reach the action as environment variables and are passed to the `pr

Plain Node with zero dependencies and no build step. Inputs arrive as `INPUT_*` environment variables; outputs and state go to `$GITHUB_OUTPUT` and `$GITHUB_STATE`.

CI tests the action in three ways. Unit tests cover the scripts. A matrix runs the exact arguments the action passes against real `prisma` CLIs, including the npm `latest` tag. An end-to-end job runs the action itself (`uses: ./`) on the small app in `e2e/app`: it deploys to a new preview environment, checks the outputs and that the service answers, then destroys the environment. It runs once with the app's pinned versions and once moved to `prisma@latest`. The end-to-end job needs the `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID` secrets. A sweep step destroys `e2e-*` environments whose run has finished, which are ones an earlier run could not destroy. It fails only when such an environment is more than a day old. To remove one by hand, run `ENVIRONMENT=<name> bun scripts/destroy.ts` in `e2e/app` with `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID` set. The end-to-end job covers the `bun install` path with the app's own `prisma` devDependency. It does not cover `npm ci` or the `prisma-version` input. A second end-to-end job runs the action on `e2e/single-app`, an app with no Composer module, with `prisma@latest`. The action cannot destroy that deploy, so each run deploys into a Project of its own, named `cloud-deploy-action-e2e-single-<run id>-<attempt>`, and deletes the Project afterwards. A pull request run deploys to an environment named after its branch, and a run on `main` deploys to production. The job also deletes such Projects whose run has finished, and fails only when one is more than a day old. To remove one by hand, run `prisma project delete <project id> --confirm <project id>`. CI also runs every 6 hours. A failed or cancelled job on `main`, on a scheduled run, on a manual run or on a `prisma-released` dispatch posts to Slack through the `SLACK_WEBHOOK_URL` secret.
CI tests the action in three ways. Unit tests cover the scripts. A matrix runs the exact arguments the action passes against real `prisma` CLIs, including the npm `latest` tag. An end-to-end job runs the action itself (`uses: ./`) on the small app in `e2e/app`: it deploys to a new preview environment, checks the outputs and that the service answers, then destroys the environment. It runs once with the app's pinned versions and once moved to `prisma@latest`. The end-to-end job needs the `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID` secrets. A sweep step destroys `e2e-*` environments whose run has finished, which are ones an earlier run could not destroy. It fails only when such an environment is more than a day old. To remove one by hand, run `ENVIRONMENT=<name> bun scripts/destroy.ts` in `e2e/app` with `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID` set. The end-to-end job covers the `bun install` path with the app's own `prisma` devDependency. It does not cover `npm ci` or the `prisma-version` input. A second end-to-end job runs the action on two apps with no Composer module: `e2e/single-app`, with `prisma@latest`, and `e2e/single-app-config`, which has a `prisma.config.ts` and its own `prisma` in its lockfile. The action cannot destroy such a deploy, so each job deploys into a Project of its own, named `cloud-deploy-action-e2e-single-<run id>-<attempt>-<matrix entry>`, and deletes the Project afterwards. A pull request run deploys to an environment named after its branch, and a run on `main` deploys to production. The job also deletes such Projects whose run has finished, and fails only when one is more than a day old. To remove one by hand, run `prisma project delete <project id> --confirm <project id>`. CI also runs every 6 hours. A failed or cancelled job on `main`, on a scheduled run, on a manual run or on a `prisma-released` dispatch posts to Slack through the `SLACK_WEBHOOK_URL` secret.

Publishing a `v1.x.y` release, or promoting a prerelease to one, moves the `v1` tag to the newest published `v1.x.y` release (`.github/workflows/major-tag.yml`). Publishing a prerelease never moves it. To move it by hand, run that workflow.

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
description: Your build command, run verbatim in both modes; the exact value "none" skips the build phase. Not used in single-app mode, where the Prisma CLI builds the Service
default: npm run build
install-command:
description: Empty auto-detects from the lockfile (npm ci or bun install --frozen-lockfile). Not used in single-app mode, where the Prisma CLI installs the dependencies
description: Empty auto-detects from the lockfile (npm ci or bun install --frozen-lockfile; a Composer module with pnpm or yarn must set this). In single-app mode the Prisma CLI installs the dependencies, and the action installs first only when the repository has a prisma.config.ts, in the folder with the lockfile, and then also detects pnpm and yarn
default: ""
module:
description: Path to your app's Composer module. Empty uses module.ts when it exists; a repository with no module.ts deploys in single-app mode
Expand All @@ -24,7 +24,7 @@ inputs:
deprecationMessage: Use the environment input instead of stage.
default: ""
prisma-version:
description: Runs this prisma version via bunx when the repository has no prisma devDependency. Empty refuses to deploy such a repository, since the CLI must match the app's Composer version. Single-app mode always runs this version through npx, and the newest one when empty
description: Runs this prisma version via bunx when the repository has no prisma devDependency. Empty refuses to deploy such a repository, since the CLI must match the app's Composer version. Single-app mode runs this version through npx, and the newest one when empty; a repository with a prisma.config.ts and its own prisma (8.0.0-rc.37 or later) runs its own when this is empty
default: ""
working-directory:
description: Where install, build, and deploy run
Expand Down
62 changes: 46 additions & 16 deletions cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ export function takesEnvironmentFlag(version) {
return isAtLeastRc(version, 30);
}

/**
* Whether this `prisma` CLI deploys a repository with no Composer module.
* 8.0.0-rc.37 is the first that does.
*
* @param {string} version - e.g. "8.0.0-rc.37".
* @returns {boolean}
*/
export function deploysWithoutComposerModule(version) {
return isAtLeastRc(version, 37);
}

/**
* The nearest directory, from `workdir` up to `root`, that holds a file with
* one of `names`. Null when none does.
*
* @param {string[]} names
* @param {string} workdir
* @param {string} root - The repository root; the search does not go above it.
* @returns {string | null}
*/
export function nearestDirectoryWith(names, workdir, root) {
for (let dir = workdir; ; dir = dirname(dir)) {
if (names.some((name) => existsSync(join(dir, name)))) return dir;
if (dirname(dir) === dir || relative(root, dir) === "") return null;
}
}

/**
* The `prisma` CLI `bun run` finds from `workdir`: the nearest
* node_modules/.bin/prisma in `workdir` or a parent, up to `root`, so a
Expand Down Expand Up @@ -150,27 +177,30 @@ export const SINGLE_APP_PRISMA_VERSION = "latest";
* Returns [cmd, args, logLabel] for deploying a repository with no Composer
* module. The CLI runs under Node.js through npx, so the repository's own
* install and build commands run under the Node.js the workflow set up, not
* under Bun's `node` shim. The action has not installed the repository's
* dependencies, so there is no local CLI to prefer. The CLI deploys into the
* Project that has the Service's name. A Composer module states that name
* itself; here it is the `name` input, else what the CLI reads from package.json.
* under Bun's `node` shim. The CLI deploys into the Project that has the
* Service's name. A Composer module states that name itself; here it is the
* `name` input, else what the CLI reads from package.json.
*
* `localVersion` is the version of the repository's own installed CLI, when
* the action installed the repository and that CLI is to run. A config file is
* built with the repository's copy of the Prisma packages, so the CLI from the
* same install must read it.
*
* @param {string} prismaVersion - The prisma-version input; empty uses SINGLE_APP_PRISMA_VERSION.
* @param {string} environment - Empty for production.
* @param {string} name - The name input; empty lets the CLI choose the name.
* @param {string | null} [localVersion] - Null runs a CLI fetched by npx.
* @returns {[string, string[], string]}
*/
export function singleAppCliCommand(prismaVersion, environment, name) {
export function singleAppCliCommand(prismaVersion, environment, name, localVersion = null) {
const deploy = ["deploy", ...(name ? ["--name", name] : []), ...(environment ? ["--environment", environment] : [])];
if (localVersion !== null) {
return [
"npx",
["--no-install", "prisma", ...deploy],
`single-app mode: the repository's own prisma ${localVersion} (npx --no-install)`,
];
}
const version = prismaVersion || SINGLE_APP_PRISMA_VERSION;
return [
"npx",
[
"--yes",
`prisma@${version}`,
"deploy",
...(name ? ["--name", name] : []),
...(environment ? ["--environment", environment] : []),
],
`single-app mode: prisma@${version} (npx)`,
];
return ["npx", ["--yes", `prisma@${version}`, ...deploy], `single-app mode: prisma@${version} (npx)`];
}
8 changes: 4 additions & 4 deletions e2e/single-app-cleanup.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Deletes the Project this run deployed e2e/single-app into, then the Projects
// of finished runs that could not delete their own. The action cannot destroy
// a deploy with no Composer module, so each run gets a Project of its own,
// named cloud-deploy-action-e2e-single-<run id>-<attempt>. A leftover that
// will not go away fails the job only once it is a day old.
// a deploy with no Composer module, so each job gets a Project of its own,
// named cloud-deploy-action-e2e-single-<run id>-<attempt>-<matrix entry>. A
// leftover that will not go away fails the job only once it is a day old.
import { spawnSync } from "node:child_process";
import { finishedRun } from "./finished-run.mjs";

const RUN_PROJECT_RE = /^cloud-deploy-action-e2e-single-(\d+)-\d+$/;
const RUN_PROJECT_RE = /^cloud-deploy-action-e2e-single-(\d+)-\d+(?:-[a-z]+)?$/;
const DAY_MS = 24 * 60 * 60 * 1000;
const { PROJECT = "" } = process.env;
if (!RUN_PROJECT_RE.test(PROJECT)) throw new Error(`refusing to delete "${PROJECT}": not a Project of this job`);
Expand Down
3 changes: 3 additions & 0 deletions e2e/single-app-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run.json
node_modules/
.prisma/
Loading
Loading