From 4db2e4d659875876ecff210c75c1144bf3041ede Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 17 Nov 2026 07:28:26 +1100 Subject: [PATCH 1/5] ci: run prisma/cloud-deploy-action's CLI test on pull requests and dev builds prisma 8.0.0-rc.30 renamed `prisma deploy --stage` to `--environment` and every cloud-deploy-action user's preview deploy failed for a week, because nothing here ran the action's arguments. The required Test check now builds `prisma` and runs the action's tests/prisma-cli.test.mjs from its v1 tag against it, so a change the released action cannot drive cannot merge. A new workflow runs the same test against each published dev build and alerts Slack on failure, without holding or failing the publish. Also corrects the stale claim that bare `prisma` still serves Prisma 7 under `latest`. Co-Authored-By: Claude Fable 5.2 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/cloud-deploy-action-dev.yml | 93 +++++++++++++++++++ .github/workflows/pr-quality.yml | 24 +++++ .github/workflows/publish.yml | 19 ++++ docs/oss/release-automation.md | 12 ++- 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cloud-deploy-action-dev.yml diff --git a/.github/workflows/cloud-deploy-action-dev.yml b/.github/workflows/cloud-deploy-action-dev.yml new file mode 100644 index 00000000..6aa124f4 --- /dev/null +++ b/.github/workflows/cloud-deploy-action-dev.yml @@ -0,0 +1,93 @@ +name: Cloud deploy action against the dev build + +# An early warning, not a blocker: the dev build must stay published so +# prisma/cloud-deploy-action can be fixed against it. The Test check on +# pull requests runs the same test and blocks the release instead. + +on: + workflow_run: + workflows: ["Publish to npm"] + types: [completed] + +permissions: {} + +jobs: + dev-build: + name: prisma/cloud-deploy-action@v1 can drive the dev build + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + + steps: + # publish.yml uploads this artifact only after it really published. + - name: Find the published dev version + id: dev + env: + GH_TOKEN: ${{ github.token }} + PUBLISH_RUN_ID: ${{ github.event.workflow_run.id }} + run: | + artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/artifacts" \ + --jq '.artifacts[] | select(.name == "dev-version") | .id') + if [ -z "$artifact" ]; then + echo "Publish run $PUBLISH_RUN_ID published no dev build. Nothing to check." + exit 0 + fi + gh run download "$PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --name dev-version --dir "$RUNNER_TEMP/dev-version" + version=$(cat "$RUNNER_TEMP/dev-version/version") + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$ ]]; then + echo "::error::The dev-version artifact holds \"$version\", which is not a version." + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: Set up Node.js + if: ${{ steps.dev.outputs.version != '' }} + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 24 + + - name: Install prisma@${{ steps.dev.outputs.version }} + if: ${{ steps.dev.outputs.version != '' }} + env: + VERSION: ${{ steps.dev.outputs.version }} + run: npm install --prefix "$RUNNER_TEMP/prisma-dev" --no-save --no-package-lock "prisma@$VERSION" + + - name: Check out prisma/cloud-deploy-action@v1 + if: ${{ steps.dev.outputs.version != '' }} + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + repository: prisma/cloud-deploy-action + ref: v1 + persist-credentials: false + + - name: prisma/cloud-deploy-action@v1 can drive prisma@${{ steps.dev.outputs.version }} + id: drive + if: ${{ steps.dev.outputs.version != '' }} + run: | + bin="$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" + if [ ! -x "$bin" ]; then + echo "::error::The installed prisma executable $bin is missing or not executable." + exit 1 + fi + PRISMA_CLI_BINS="$bin" node --test tests/prisma-cli.test.mjs + + - name: Alert Slack + if: ${{ failure() && steps.drive.outcome == 'failure' }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + VERSION: ${{ steps.dev.outputs.version }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + if [ -z "$SLACK_WEBHOOK_URL" ]; then + echo "::error::SLACK_WEBHOOK_URL is not configured, so nobody was told that prisma@$VERSION breaks prisma/cloud-deploy-action@v1." + exit 1 + fi + payload=$(jq -n \ + --arg version "$VERSION" \ + --arg run "$RUN_URL" \ + '{text: "The dev build prisma@\($version) fails the prisma/cloud-deploy-action test: the released action (v1) cannot drive it. The next prisma CLI release will be blocked until the action is updated to support it.\nRun: \($run)"}') + curl --fail-with-body --silent --show-error \ + -H "Content-Type: application/json" \ + --data "$payload" \ + "$SLACK_WEBHOOK_URL" diff --git a/.github/workflows/pr-quality.yml b/.github/workflows/pr-quality.yml index c2fd9efb..92fe2786 100644 --- a/.github/workflows/pr-quality.yml +++ b/.github/workflows/pr-quality.yml @@ -182,3 +182,27 @@ jobs: env: PUBLISH_CHANNEL: dev run: pnpm check:conformance + + # prisma/cloud-deploy-action runs `prisma deploy` with fixed + # arguments. `v1` is the moving tag users run, so a CLI change that + # breaks those arguments fails here, before it can be released. + - name: Build the prisma package + run: pnpm exec turbo run build --filter=prisma + + - name: Check out prisma/cloud-deploy-action@v1 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + repository: prisma/cloud-deploy-action + ref: v1 + path: .reference/cloud-deploy-action + persist-credentials: false + + - name: prisma/cloud-deploy-action@v1 can drive this CLI + working-directory: .reference/cloud-deploy-action + run: | + bin="$GITHUB_WORKSPACE/packages/prisma/dist/prisma.js" + if [ ! -x "$bin" ]; then + echo "::error::The built prisma executable $bin is missing or not executable." + exit 1 + fi + PRISMA_CLI_BINS="$bin" node --test tests/prisma-cli.test.mjs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b06460c8..e1b193cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -121,6 +121,25 @@ jobs: "@prisma/cli@$DEV_VERSION" \ "prisma@$DEV_VERSION" + # Read by cloud-deploy-action-dev.yml, which runs as its own + # workflow so its result never holds or fails this one. + - name: Record the published dev version + if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} + env: + DEV_VERSION: ${{ steps.version.outputs.devVersion }} + run: | + mkdir -p "$RUNNER_TEMP/dev-version" + printf '%s\n' "$DEV_VERSION" > "$RUNNER_TEMP/dev-version/version" + + - name: Upload the published dev version + if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: dev-version + path: ${{ runner.temp }}/dev-version/version + if-no-files-found: error + retention-days: 7 + # --- The release: only when the committed version changed. --- - name: Restore the committed versions diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 6675eccb..a825ae54 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -15,7 +15,7 @@ A **release** of the CLI depends only on **released** versions of the products. ## What happens when a product publishes 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. -2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. Every watched package publishes its releases under `latest`, pre-release versions included: they are all new packages with no pre-8 audience to protect. Holding `latest` back behind `next` matters only for the bare `prisma` name, which this repository publishes and which still serves Prisma 7 there until the deliberate cutover. Each package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". +2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. Every watched package publishes its releases under `latest`, pre-release versions included: they are all new packages with no pre-8 audience to protect. The bare `prisma` name, which this repository publishes, was the one exception: its `latest` served Prisma 7 until the 2026-08-25 cutover, and since then every release of it publishes under `latest` too (see [versioning.md](versioning.md)). Each package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. 4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `latest` with the committed product versions, plus the usual `dev` build. @@ -23,6 +23,15 @@ A product release reaches a released CLI with no person in the loop, as long as A **daily schedule** runs the same comparison, so a lost dispatch event delays an update by at most a day rather than indefinitely. `workflow_dispatch` runs it on demand. +## Keeping `prisma/cloud-deploy-action` working + +[`prisma/cloud-deploy-action`](https://github.com/prisma/cloud-deploy-action) runs `prisma deploy` with fixed arguments. When `prisma@8.0.0-rc.30` renamed `--stage` to `--environment`, every user's preview deploy failed for a week, because nothing here ran the action's arguments. Two checks now run the action's own test, `tests/prisma-cli.test.mjs` at its moving `v1` tag (what users run), against this CLI: + +- **On every pull request**, the required `Test` check in [`pr-quality.yml`](../../.github/workflows/pr-quality.yml) builds `prisma` and runs the test against it. A change the released action cannot drive cannot merge, so it cannot be released. +- **After every dev build is published**, [`cloud-deploy-action-dev.yml`](../../.github/workflows/cloud-deploy-action-dev.yml) installs that dev version from npm and runs the test. It never blocks or fails the publish, because the action has to be fixed against that dev build. A failure posts to Slack through the `SLACK_WEBHOOK_URL` secret; the job fails with an error if the secret is missing. + +An intended breaking change to the `prisma deploy` arguments goes like this. The dev build, which depends on the products' dev builds, carries the change first, and the dev check alerts Slack. A maintainer then releases a version of the action that accepts both the old and the new arguments and moves its `v1` tag to it. Until then the release pull request that brings in the change fails its `Test` check and cannot merge; once `v1` moves, a re-run passes and it merges. + ## The shared secret: `DEPLOY_GITHUB_TOKEN` One fine-grained personal access token, stored under the same secret name in all three repositories. @@ -76,6 +85,7 @@ A workflow step that must run should fail when its secret or token is missing, n | Checks pass but the pull request does not merge | The `main` ruleset requires one approving review, which CodeRabbit gives; it commented or was rate-limited instead | Approve the pull request by hand | | `main` holds product pins no release shipped | A release took the version number before the follow pull request merged | The next run (the daily schedule at the latest) compares `main`'s pins with the last release's tag and opens a release for them; dispatch the workflow to do it now | | A published version never appears on the registry | npm accepted the publish but the version is not resolvable | The publish run polls for it and fails if it never appears; if that fails, re-dispatch the workflow — an already-published version is treated as done, so only the missing one publishes | +| A release pull request fails "prisma/cloud-deploy-action@v1 can drive this CLI" | The CLI changed the arguments `prisma deploy` accepts, and the released action still sends the old ones | Release the action with support for both and move its `v1` tag, then re-run the check (see above) | | A release publish fails on the dev-build check | The committed pins are dev builds — a dev stamp was committed by mistake, or a product has no usable release | Run `node scripts/update-product-versions.mjs --channel release`; if that changes nothing, the product must publish a real release | ## The state this replaced From d1fe0e7953a789e07ea131913e545f82c77d27bf Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 17 Nov 2026 07:38:17 +1100 Subject: [PATCH 2/5] ci: share one cloud-deploy-action check script, and make the dev-build check report every failure Both checks now run scripts/check-cloud-deploy-action.mjs, which fails unless the action's two deploy cases ran and passed. Before, a renamed PRISMA_CLI_BINS in the action made the test run zero cases and pass. The record and upload steps in publish.yml can no longer fail a release. The dev-build check, renamed to check-dev-build-with-cloud-deploy-action.yml and limited to main, checks the Slack secret on every run, alerts on any failure, says whether the action cannot drive the build or the check could not run, and treats a successful push publish without the artifact as an error. Both checks take the action ref from the CLOUD_DEPLOY_ACTION_REF repository variable, defaulting to v1. The docs now explain why there are two checks, the version-based flow for an intended argument change, the contract with the action, and the escapes when v1 is broken. Co-Authored-By: Claude Fable 5.2 Signed-off-by: willbot Signed-off-by: Will Madden --- ...eck-dev-build-with-cloud-deploy-action.yml | 119 ++++++++++++++++++ .github/workflows/cloud-deploy-action-dev.yml | 93 -------------- .github/workflows/pr-quality.yml | 18 +-- .github/workflows/publish.yml | 11 +- docs/oss/release-automation.md | 37 +++++- package.json | 2 +- scripts/check-cloud-deploy-action.mjs | 108 ++++++++++++++++ scripts/check-cloud-deploy-action.test.mjs | 49 ++++++++ 8 files changed, 322 insertions(+), 115 deletions(-) create mode 100644 .github/workflows/check-dev-build-with-cloud-deploy-action.yml delete mode 100644 .github/workflows/cloud-deploy-action-dev.yml create mode 100644 scripts/check-cloud-deploy-action.mjs create mode 100644 scripts/check-cloud-deploy-action.test.mjs diff --git a/.github/workflows/check-dev-build-with-cloud-deploy-action.yml b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml new file mode 100644 index 00000000..6c455eee --- /dev/null +++ b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml @@ -0,0 +1,119 @@ +name: cloud-deploy-action can drive the dev build + +# An early warning, not a blocker: the dev build must stay published so +# prisma/cloud-deploy-action can be fixed against it. The Test check on +# pull requests runs the same test and blocks the release instead. +# See docs/oss/release-automation.md. + +on: + workflow_run: + workflows: ["Publish to npm"] + types: [completed] + branches: [main] + +permissions: {} + +jobs: + cloud-deploy-action-drives-dev-build: + name: prisma/cloud-deploy-action can drive the dev build + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + env: + ACTION_REF: ${{ vars.CLOUD_DEPLOY_ACTION_REF || 'v1' }} + + steps: + # Checked on every run so a missing secret shows up at the first + # publish, not at the first incompatibility. + - name: Check that SLACK_WEBHOOK_URL is set + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + run: | + if [ -z "$SLACK_WEBHOOK_URL" ]; then + echo "::error::The SLACK_WEBHOOK_URL secret is not set, so this check cannot report a failure." + exit 1 + fi + + # publish.yml uploads this artifact only after it really published. + - name: Find the published dev version + id: dev + env: + GH_TOKEN: ${{ github.token }} + PUBLISH_RUN_ID: ${{ github.event.workflow_run.id }} + PUBLISH_EVENT: ${{ github.event.workflow_run.event }} + PUBLISH_CONCLUSION: ${{ github.event.workflow_run.conclusion }} + run: | + artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/artifacts" \ + --jq '.artifacts[] | select(.name == "published-dev-version") | .id') + if [ -z "$artifact" ]; then + if [ "$PUBLISH_EVENT" = push ] && [ "$PUBLISH_CONCLUSION" = success ]; then + echo "::error::Publish run $PUBLISH_RUN_ID succeeded on a push but has no published-dev-version artifact." + exit 1 + fi + echo "Publish run $PUBLISH_RUN_ID ($PUBLISH_EVENT, $PUBLISH_CONCLUSION) published no dev build. Nothing to check." + exit 0 + fi + gh run download "$PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --name published-dev-version --dir "$RUNNER_TEMP/published-dev-version" + version=$(cat "$RUNNER_TEMP/published-dev-version/version") + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$ ]]; then + echo "::error::The published-dev-version artifact holds \"$version\", which is not a version." + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: Checkout + if: ${{ steps.dev.outputs.version != '' }} + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + - name: Set up Node.js + if: ${{ steps.dev.outputs.version != '' }} + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: .node-version + + - name: Install prisma@${{ steps.dev.outputs.version }} + if: ${{ steps.dev.outputs.version != '' }} + env: + VERSION: ${{ steps.dev.outputs.version }} + run: npm install --prefix "$RUNNER_TEMP/prisma-dev" --no-save --no-package-lock "prisma@$VERSION" + + - name: Check out prisma/cloud-deploy-action + if: ${{ steps.dev.outputs.version != '' }} + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + repository: prisma/cloud-deploy-action + ref: ${{ env.ACTION_REF }} + path: .reference/cloud-deploy-action + persist-credentials: false + + - name: prisma/cloud-deploy-action can drive prisma@${{ steps.dev.outputs.version }} + id: drive + if: ${{ steps.dev.outputs.version != '' }} + run: node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action "$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" + + - name: Alert Slack + if: ${{ failure() }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + DRIVE_OUTCOME: ${{ steps.drive.outcome }} + VERSION: ${{ steps.dev.outputs.version }} + PUBLISH_RUN_URL: ${{ github.event.workflow_run.html_url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + if [ -z "$SLACK_WEBHOOK_URL" ]; then + echo "::error::The SLACK_WEBHOOK_URL secret is not set, so this failure was not reported." + exit 1 + fi + if [ "$DRIVE_OUTCOME" = failure ]; then + text="The dev build prisma@$VERSION fails prisma/cloud-deploy-action's test: the released action ($ACTION_REF) cannot drive it. The next prisma CLI release will be blocked until an action release supports this build. This alert repeats on each merge to prisma-cli's main until then." + else + text="The check that prisma/cloud-deploy-action can drive the dev build could not run, so the dev build was not tested: the published dev version artifact is missing or unreadable, npm install failed, or a checkout failed. Publish run: $PUBLISH_RUN_URL" + fi + payload=$(jq -n --arg text "$text" --arg run "$RUN_URL" '{text: "\($text)\nRun: \($run)"}') + curl --fail-with-body --silent --show-error \ + -H "Content-Type: application/json" \ + --data "$payload" \ + "$SLACK_WEBHOOK_URL" diff --git a/.github/workflows/cloud-deploy-action-dev.yml b/.github/workflows/cloud-deploy-action-dev.yml deleted file mode 100644 index 6aa124f4..00000000 --- a/.github/workflows/cloud-deploy-action-dev.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Cloud deploy action against the dev build - -# An early warning, not a blocker: the dev build must stay published so -# prisma/cloud-deploy-action can be fixed against it. The Test check on -# pull requests runs the same test and blocks the release instead. - -on: - workflow_run: - workflows: ["Publish to npm"] - types: [completed] - -permissions: {} - -jobs: - dev-build: - name: prisma/cloud-deploy-action@v1 can drive the dev build - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - - steps: - # publish.yml uploads this artifact only after it really published. - - name: Find the published dev version - id: dev - env: - GH_TOKEN: ${{ github.token }} - PUBLISH_RUN_ID: ${{ github.event.workflow_run.id }} - run: | - artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/artifacts" \ - --jq '.artifacts[] | select(.name == "dev-version") | .id') - if [ -z "$artifact" ]; then - echo "Publish run $PUBLISH_RUN_ID published no dev build. Nothing to check." - exit 0 - fi - gh run download "$PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --name dev-version --dir "$RUNNER_TEMP/dev-version" - version=$(cat "$RUNNER_TEMP/dev-version/version") - if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$ ]]; then - echo "::error::The dev-version artifact holds \"$version\", which is not a version." - exit 1 - fi - echo "version=$version" >> "$GITHUB_OUTPUT" - - - name: Set up Node.js - if: ${{ steps.dev.outputs.version != '' }} - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 - with: - node-version: 24 - - - name: Install prisma@${{ steps.dev.outputs.version }} - if: ${{ steps.dev.outputs.version != '' }} - env: - VERSION: ${{ steps.dev.outputs.version }} - run: npm install --prefix "$RUNNER_TEMP/prisma-dev" --no-save --no-package-lock "prisma@$VERSION" - - - name: Check out prisma/cloud-deploy-action@v1 - if: ${{ steps.dev.outputs.version != '' }} - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - with: - repository: prisma/cloud-deploy-action - ref: v1 - persist-credentials: false - - - name: prisma/cloud-deploy-action@v1 can drive prisma@${{ steps.dev.outputs.version }} - id: drive - if: ${{ steps.dev.outputs.version != '' }} - run: | - bin="$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" - if [ ! -x "$bin" ]; then - echo "::error::The installed prisma executable $bin is missing or not executable." - exit 1 - fi - PRISMA_CLI_BINS="$bin" node --test tests/prisma-cli.test.mjs - - - name: Alert Slack - if: ${{ failure() && steps.drive.outcome == 'failure' }} - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - VERSION: ${{ steps.dev.outputs.version }} - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: | - if [ -z "$SLACK_WEBHOOK_URL" ]; then - echo "::error::SLACK_WEBHOOK_URL is not configured, so nobody was told that prisma@$VERSION breaks prisma/cloud-deploy-action@v1." - exit 1 - fi - payload=$(jq -n \ - --arg version "$VERSION" \ - --arg run "$RUN_URL" \ - '{text: "The dev build prisma@\($version) fails the prisma/cloud-deploy-action test: the released action (v1) cannot drive it. The next prisma CLI release will be blocked until the action is updated to support it.\nRun: \($run)"}') - curl --fail-with-body --silent --show-error \ - -H "Content-Type: application/json" \ - --data "$payload" \ - "$SLACK_WEBHOOK_URL" diff --git a/.github/workflows/pr-quality.yml b/.github/workflows/pr-quality.yml index 92fe2786..00fe8f15 100644 --- a/.github/workflows/pr-quality.yml +++ b/.github/workflows/pr-quality.yml @@ -185,24 +185,18 @@ jobs: # prisma/cloud-deploy-action runs `prisma deploy` with fixed # arguments. `v1` is the moving tag users run, so a CLI change that - # breaks those arguments fails here, before it can be released. + # breaks those arguments fails here, before it can be released. See + # docs/oss/release-automation.md for CLOUD_DEPLOY_ACTION_REF. - name: Build the prisma package run: pnpm exec turbo run build --filter=prisma - - name: Check out prisma/cloud-deploy-action@v1 + - name: Check out prisma/cloud-deploy-action uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: repository: prisma/cloud-deploy-action - ref: v1 + ref: ${{ vars.CLOUD_DEPLOY_ACTION_REF || 'v1' }} path: .reference/cloud-deploy-action persist-credentials: false - - name: prisma/cloud-deploy-action@v1 can drive this CLI - working-directory: .reference/cloud-deploy-action - run: | - bin="$GITHUB_WORKSPACE/packages/prisma/dist/prisma.js" - if [ ! -x "$bin" ]; then - echo "::error::The built prisma executable $bin is missing or not executable." - exit 1 - fi - PRISMA_CLI_BINS="$bin" node --test tests/prisma-cli.test.mjs + - name: prisma/cloud-deploy-action can drive this CLI + run: node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action packages/prisma/dist/prisma.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e1b193cf..efaa9e6d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish to npm +name: Publish to npm # check-dev-build-with-cloud-deploy-action.yml finds this workflow by this name # Every run publishes a dev build. A run also publishes a release when # the push changed the root `version`, or a dispatch asked for one. The @@ -121,10 +121,11 @@ jobs: "@prisma/cli@$DEV_VERSION" \ "prisma@$DEV_VERSION" - # Read by cloud-deploy-action-dev.yml, which runs as its own - # workflow so its result never holds or fails this one. + # Read by check-dev-build-with-cloud-deploy-action.yml, which runs as + # its own workflow so its result never holds or fails this one. - name: Record the published dev version if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} + continue-on-error: true env: DEV_VERSION: ${{ steps.version.outputs.devVersion }} run: | @@ -133,11 +134,13 @@ jobs: - name: Upload the published dev version if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} + continue-on-error: true uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: - name: dev-version + name: published-dev-version path: ${{ runner.temp }}/dev-version/version if-no-files-found: error + overwrite: true retention-days: 7 # --- The release: only when the committed version changed. --- diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index a825ae54..9789b93e 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -8,6 +8,8 @@ The unified CLI is assembled from three repositories. This page explains how a n | `prisma/composer` | `@prisma/composer-cli` (and the `@prisma/composer` library) | a dependency of the shell | | `prisma/prisma` | `@prisma/orm-toolchain` | a dependency of the shell | +One more repository depends on this CLI instead of feeding it: `prisma/cloud-deploy-action`, whose test this repository runs (see [Keeping `prisma/cloud-deploy-action` working](#keeping-prismacloud-deploy-action-working)). + ## The rule A **release** of the CLI depends only on **released** versions of the products. A **dev build** of the CLI depends on the products' **dev builds** (operator ruling 2026-08-17). Nothing in between, and nothing hand-maintained. @@ -25,12 +27,35 @@ A **daily schedule** runs the same comparison, so a lost dispatch event delays a ## Keeping `prisma/cloud-deploy-action` working -[`prisma/cloud-deploy-action`](https://github.com/prisma/cloud-deploy-action) runs `prisma deploy` with fixed arguments. When `prisma@8.0.0-rc.30` renamed `--stage` to `--environment`, every user's preview deploy failed for a week, because nothing here ran the action's arguments. Two checks now run the action's own test, `tests/prisma-cli.test.mjs` at its moving `v1` tag (what users run), against this CLI: +[`prisma/cloud-deploy-action`](https://github.com/prisma/cloud-deploy-action) runs `prisma deploy` with arguments it builds itself. When `prisma@8.0.0-rc.30` renamed `--stage` to `--environment`, every user's preview deploy failed for a week, because nothing here ran the action's arguments. Two checks now run the action's own test against this CLI, both through [`scripts/check-cloud-deploy-action.mjs`](../../scripts/check-cloud-deploy-action.mjs): + +- **The pull request check.** The required `Test` check in [`pr-quality.yml`](../../.github/workflows/pr-quality.yml) builds `prisma` from the pull request and runs the test against it. That CLI uses the products' released versions, which is what the next release ships. A CLI the released action cannot drive cannot merge, so it cannot be released. +- **The dev-build check.** [`check-dev-build-with-cloud-deploy-action.yml`](../../.github/workflows/check-dev-build-with-cloud-deploy-action.yml) runs after each publish from `main`, installs the dev build that run published, and runs the test against it. That CLI uses the products' dev builds, which is what a later release will ship. It runs at the next merge to this repository's `main` after a product publishes a dev build, not at the moment the product publishes. It never holds or fails the publish. On any failure it posts to Slack through the `SLACK_WEBHOOK_URL` secret, and the message says whether the action cannot drive the dev build or the check itself could not run. Every run checks the secret in its first step and fails if it is not set. + +The pull request check is part of the `Test` job because that check is already required on `main`. It should move to its own required job the next time the `main` ruleset is changed. + +### What this repository relies on in the action + +- The test is `tests/prisma-cli.test.mjs`, and it needs no install: it imports only `../cli.mjs` and Node built-ins. +- The test reads the executable to test from the `PRISMA_CLI_BINS` environment variable. +- The script fails unless the two deploy cases (`... accepts the deploy arguments for production` and for a named environment) ran and passed. Without an executable the test runs no cases and passes, so a renamed variable would otherwise go unnoticed. The destroy case may be skipped, because CLIs without a `destroy` command skip it. +- The test reads this CLI's error codes: `CLI.INVALID_ARGUMENTS`, `CLI.COMMAND_MOVED` or `CLI.UNKNOWN_COMMAND` for rejected arguments, and `CLI.CREDENTIALS_REQUIRED` or `CLI.CONFIG_SECTION_INVALID` as the first check after the arguments are parsed. + +Both checks use the action at `v1`, its moving release tag, which is what users run. The repository variable `CLOUD_DEPLOY_ACTION_REF` replaces `v1` in both. + +### Changing the `deploy` arguments on purpose + +The action chooses the arguments from the CLI's version number. It does not ask the CLI. For example, `takesEnvironmentFlag` in its `cli.mjs` sends `--environment` to 8.0.0-rc.30 and later, and `--stage` to earlier versions. A dev build carries the version of the last release plus `-dev.N` (for example `8.0.0-rc.34-dev.812`), and the action's current rule treats it as that release. So the action cannot tell a dev build with changed arguments from the unchanged release with the same base version. + +When a product changes the arguments: + +1. The product publishes a dev build with the change. At the next merge to `main` here, the CLI's dev build picks it up, and the dev-build check fails and alerts Slack. +2. The dev-build check stays red, and alerts again on each merge to `main`, until an action release has a rule that covers those dev builds. +3. The product releases the change, and the release pull request bumps the CLI to a new version. It passes only once the action is released, and `v1` moved, with a rule that sends the new arguments to that version (for example "rc.35 and later"). Then re-run its `Test` check. -- **On every pull request**, the required `Test` check in [`pr-quality.yml`](../../.github/workflows/pr-quality.yml) builds `prisma` and runs the test against it. A change the released action cannot drive cannot merge, so it cannot be released. -- **After every dev build is published**, [`cloud-deploy-action-dev.yml`](../../.github/workflows/cloud-deploy-action-dev.yml) installs that dev version from npm and runs the test. It never blocks or fails the publish, because the action has to be fixed against that dev build. A failure posts to Slack through the `SLACK_WEBHOOK_URL` secret; the job fails with an error if the secret is missing. +When the change is made in this repository itself, the pull request's CLI reports the last release's version, so the action sends it the old arguments and the check fails. Release the action first with a rule for the next version, and bump the version (`pnpm bump-version`) in the same pull request. -An intended breaking change to the `prisma deploy` arguments goes like this. The dev build, which depends on the products' dev builds, carries the change first, and the dev check alerts Slack. A maintainer then releases a version of the action that accepts both the old and the new arguments and moves its `v1` tag to it. Until then the release pull request that brings in the change fails its `Test` check and cannot merge; once `v1` moves, a re-run passes and it merges. +Making the action detect the arguments without relying on the version number is tracked as follow-up in `prisma/cloud-deploy-action`. ## The shared secret: `DEPLOY_GITHUB_TOKEN` @@ -85,7 +110,9 @@ A workflow step that must run should fail when its secret or token is missing, n | Checks pass but the pull request does not merge | The `main` ruleset requires one approving review, which CodeRabbit gives; it commented or was rate-limited instead | Approve the pull request by hand | | `main` holds product pins no release shipped | A release took the version number before the follow pull request merged | The next run (the daily schedule at the latest) compares `main`'s pins with the last release's tag and opens a release for them; dispatch the workflow to do it now | | A published version never appears on the registry | npm accepted the publish but the version is not resolvable | The publish run polls for it and fails if it never appears; if that fails, re-dispatch the workflow — an already-published version is treated as done, so only the missing one publishes | -| A release pull request fails "prisma/cloud-deploy-action@v1 can drive this CLI" | The CLI changed the arguments `prisma deploy` accepts, and the released action still sends the old ones | Release the action with support for both and move its `v1` tag, then re-run the check (see above) | +| A pull request fails "prisma/cloud-deploy-action can drive this CLI" | The pull request changes the arguments `prisma deploy` accepts, and the released action does not send the new ones to this version | Release the action with a rule for this version and move its `v1` tag, then re-run the check (see [Changing the `deploy` arguments on purpose](#changing-the-deploy-arguments-on-purpose)) | +| Every pull request fails "prisma/cloud-deploy-action can drive this CLI" or "Check out prisma/cloud-deploy-action" | The action's `v1` is broken, or GitHub cannot fetch `prisma/cloud-deploy-action` | Set the repository variable `CLOUD_DEPLOY_ACTION_REF` to a known-good tag of the action and re-run; delete the variable once `v1` works again. If that does not help, an administrator can bypass the `main` ruleset to merge an urgent fix | +| The dev-build check fails at "Check that SLACK_WEBHOOK_URL is set" | The secret is absent from this repository | Add a Slack incoming-webhook URL as the `SLACK_WEBHOOK_URL` repository secret | | A release publish fails on the dev-build check | The committed pins are dev builds — a dev stamp was committed by mistake, or a product has no usable release | Run `node scripts/update-product-versions.mjs --channel release`; if that changes nothing, the product must publish a real release | ## The state this replaced diff --git a/package.json b/package.json index c38ddcaa..f303c854 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "lint:fix": "biome check . --write", "bump-version": "node scripts/bump-version.ts", "test": "turbo run test", - "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs", + "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs scripts/check-cloud-deploy-action.test.mjs", "typecheck": "turbo run typecheck", "prisma-cli": "tsx packages/cli/src/bin.ts", "prisma": "tsx packages/cli/src/bin.ts", diff --git a/scripts/check-cloud-deploy-action.mjs b/scripts/check-cloud-deploy-action.mjs new file mode 100644 index 00000000..2c0c1902 --- /dev/null +++ b/scripts/check-cloud-deploy-action.mjs @@ -0,0 +1,108 @@ +#!/usr/bin/env node + +// Runs prisma/cloud-deploy-action's own CLI test against one `prisma` +// executable. The test passes with zero cases when it gets no executable +// (for example after a rename of PRISMA_CLI_BINS in the action), so this +// also requires the deploy cases to have run and passed. +// +// Usage: node scripts/check-cloud-deploy-action.mjs + +import { accessSync, constants, existsSync, statSync } from "node:fs"; +import { join, resolve } from "node:path"; +import { run } from "node:test"; +import { spec } from "node:test/reporters"; +import { pathToFileURL } from "node:url"; + +const TEST_FILE = "tests/prisma-cli.test.mjs"; +const DEPLOY_CASE = /accepts the deploy arguments for (.+)$/; + +/** + * Problems with a finished test run, or none when it counts as a pass. + * + * @param {readonly { name: string, outcome: "pass" | "fail" | "skip" }[]} results + * @returns {string[]} + */ +export function findProblems(results) { + const problems = results + .filter((result) => result.outcome === "fail") + .map((result) => `Failed: ${result.name}`); + const passedDeployTargets = results + .filter((result) => result.outcome === "pass") + .map((result) => DEPLOY_CASE.exec(result.name)?.[1]) + .filter((target) => target !== undefined); + if (!passedDeployTargets.includes("production")) { + problems.push("The deploy case for production did not run and pass."); + } + if (!passedDeployTargets.some((target) => target !== "production")) { + problems.push( + "The deploy case for a named environment did not run and pass.", + ); + } + return problems; +} + +function isExecutableFile(path) { + try { + accessSync(path, constants.X_OK); + return statSync(path).isFile(); + } catch { + return false; + } +} + +async function main() { + const [actionDir, bin] = process.argv.slice(2); + if (!(actionDir && bin)) { + console.error( + "Usage: node scripts/check-cloud-deploy-action.mjs ", + ); + process.exit(1); + } + const testFile = resolve(actionDir, TEST_FILE); + if (!existsSync(testFile)) { + console.error( + `::error::${join(actionDir, TEST_FILE)} does not exist. prisma/cloud-deploy-action must keep its CLI test at this path.`, + ); + process.exit(1); + } + const executable = resolve(bin); + if (!isExecutableFile(executable)) { + console.error( + `::error::The prisma executable ${executable} is missing or not executable.`, + ); + process.exit(1); + } + + process.env.PRISMA_CLI_BINS = executable; + /** @type {{ name: string, outcome: "pass" | "fail" | "skip" }[]} */ + const results = []; + const stream = run({ files: [testFile], cwd: resolve(actionDir) }); + stream.on("test:pass", ({ name, skip }) => { + results.push({ name, outcome: skip ? "skip" : "pass" }); + }); + stream.on("test:fail", ({ name }) => { + results.push({ name, outcome: "fail" }); + }); + for await (const chunk of stream.compose(spec)) { + process.stdout.write(chunk); + } + + const problems = findProblems(results); + if (problems.length > 0) { + for (const problem of problems) { + console.error(`::error::${problem}`); + } + console.error( + `::error::prisma/cloud-deploy-action's test did not pass against ${executable}.`, + ); + process.exit(1); + } + console.log( + `prisma/cloud-deploy-action's test passes against ${executable}.`, + ); +} + +const isDirectRun = + process.argv[1] !== undefined && + import.meta.url === pathToFileURL(process.argv[1]).href; +if (isDirectRun) await main(); diff --git a/scripts/check-cloud-deploy-action.test.mjs b/scripts/check-cloud-deploy-action.test.mjs new file mode 100644 index 00000000..b74bb4b0 --- /dev/null +++ b/scripts/check-cloud-deploy-action.test.mjs @@ -0,0 +1,49 @@ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { findProblems } from "./check-cloud-deploy-action.mjs"; + +const production = "prisma 8.0.0 accepts the deploy arguments for production"; +const named = "prisma 8.0.0 accepts the deploy arguments for pr-7"; +const destroy = "prisma 8.0.0 accepts the destroy arguments"; + +describe("findProblems", () => { + it("passes when both deploy cases pass and the destroy case is skipped", () => { + assert.deepEqual( + findProblems([ + { name: production, outcome: "pass" }, + { name: named, outcome: "pass" }, + { name: destroy, outcome: "skip" }, + ]), + [], + ); + }); + + it("fails a run with no cases, as when the action renames PRISMA_CLI_BINS", () => { + assert.equal( + findProblems([{ name: "tests/prisma-cli.test.mjs", outcome: "pass" }]) + .length, + 2, + ); + }); + + it("fails when a deploy case is skipped instead of passing", () => { + assert.deepEqual( + findProblems([ + { name: production, outcome: "pass" }, + { name: named, outcome: "skip" }, + ]), + ["The deploy case for a named environment did not run and pass."], + ); + }); + + it("fails on any failed case", () => { + assert.deepEqual( + findProblems([ + { name: production, outcome: "pass" }, + { name: named, outcome: "pass" }, + { name: destroy, outcome: "fail" }, + ]), + [`Failed: ${destroy}`], + ); + }); +}); From 11e469933b8e546941dc895181bd13e47cca399c Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 17 Nov 2026 07:46:33 +1100 Subject: [PATCH 3/5] ci: tell an incompatible CLI apart from a cloud-deploy-action check that could not run scripts/check-cloud-deploy-action.mjs now exits 1 when the action's test ran and a case failed, and 2 when the check could not run: the test file or the executable is missing, or the deploy cases did not run. The dev-build workflow records the exit code and picks the Slack message from it, so a missing file is no longer reported as an incompatibility. The incompatibility message now names the fix: a prisma/cloud-deploy-action release whose rule covers these dev builds and the next CLI version. The pass/fail rule moved to scripts/check-cloud-deploy-action-utils.mjs, and the script calls main() unconditionally. Before, it compared import.meta.url with process.argv[1] and exited 0 without running anything when started through a symbolic link. New tests run the script as a child process against a small fixture of the action's test and stub CLIs, directly and through a symbolic link. When a deploy case is missing, the error names the title the script looks for and says the action's test titles may have changed. The record and upload steps for the published dev version in publish.yml now time out after 2 minutes, so a slow artifact service cannot delay the release. Co-Authored-By: Claude Fable 5.2 Signed-off-by: willbot Signed-off-by: Will Madden --- ...eck-dev-build-with-cloud-deploy-action.yml | 25 +++-- .github/workflows/publish.yml | 2 + docs/oss/release-automation.md | 4 +- scripts/check-cloud-deploy-action-utils.mjs | 40 +++++++ scripts/check-cloud-deploy-action.mjs | 72 +++++-------- scripts/check-cloud-deploy-action.test.mjs | 101 ++++++++++++++---- scripts/fixtures/accepting-prisma | 2 + .../tests/prisma-cli.test.mjs | 25 +++++ scripts/fixtures/rejecting-prisma | 2 + 9 files changed, 202 insertions(+), 71 deletions(-) create mode 100644 scripts/check-cloud-deploy-action-utils.mjs create mode 100755 scripts/fixtures/accepting-prisma create mode 100644 scripts/fixtures/cloud-deploy-action/tests/prisma-cli.test.mjs create mode 100755 scripts/fixtures/rejecting-prisma diff --git a/.github/workflows/check-dev-build-with-cloud-deploy-action.yml b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml index 6c455eee..3ef8e3ae 100644 --- a/.github/workflows/check-dev-build-with-cloud-deploy-action.yml +++ b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml @@ -92,13 +92,17 @@ jobs: - name: prisma/cloud-deploy-action can drive prisma@${{ steps.dev.outputs.version }} id: drive if: ${{ steps.dev.outputs.version != '' }} - run: node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action "$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" + run: | + code=0 + node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action "$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" || code=$? + echo "exit-code=$code" >> "$GITHUB_OUTPUT" + exit "$code" - name: Alert Slack if: ${{ failure() }} env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - DRIVE_OUTCOME: ${{ steps.drive.outcome }} + DRIVE_EXIT_CODE: ${{ steps.drive.outputs.exit-code }} VERSION: ${{ steps.dev.outputs.version }} PUBLISH_RUN_URL: ${{ github.event.workflow_run.html_url }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} @@ -107,11 +111,18 @@ jobs: echo "::error::The SLACK_WEBHOOK_URL secret is not set, so this failure was not reported." exit 1 fi - if [ "$DRIVE_OUTCOME" = failure ]; then - text="The dev build prisma@$VERSION fails prisma/cloud-deploy-action's test: the released action ($ACTION_REF) cannot drive it. The next prisma CLI release will be blocked until an action release supports this build. This alert repeats on each merge to prisma-cli's main until then." - else - text="The check that prisma/cloud-deploy-action can drive the dev build could not run, so the dev build was not tested: the published dev version artifact is missing or unreadable, npm install failed, or a checkout failed. Publish run: $PUBLISH_RUN_URL" - fi + # Exit codes of scripts/check-cloud-deploy-action.mjs. + case "$DRIVE_EXIT_CODE" in + 1) + text="The dev build prisma@$VERSION fails prisma/cloud-deploy-action's test: the released action ($ACTION_REF) cannot drive it. The fix is a prisma/cloud-deploy-action release whose rule covers these dev builds and the next CLI version. Until then the next prisma CLI release is blocked, and this alert repeats on each merge to prisma-cli's main. See docs/oss/release-automation.md#changing-the-deploy-arguments-on-purpose." + ;; + 2) + text="The check that prisma/cloud-deploy-action can drive prisma@$VERSION could not run, so the dev build was not tested: the action's test file or the installed prisma executable is missing, or the action's deploy cases did not run. The run log says which." + ;; + *) + text="The check that prisma/cloud-deploy-action can drive the dev build could not run, so the dev build was not tested: the published dev version artifact is missing or unreadable, npm install failed, or a checkout failed. Publish run: $PUBLISH_RUN_URL" + ;; + esac payload=$(jq -n --arg text "$text" --arg run "$RUN_URL" '{text: "\($text)\nRun: \($run)"}') curl --fail-with-body --silent --show-error \ -H "Content-Type: application/json" \ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index efaa9e6d..50c4612c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -126,6 +126,7 @@ jobs: - name: Record the published dev version if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} continue-on-error: true + timeout-minutes: 2 env: DEV_VERSION: ${{ steps.version.outputs.devVersion }} run: | @@ -135,6 +136,7 @@ jobs: - name: Upload the published dev version if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} continue-on-error: true + timeout-minutes: 2 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: published-dev-version diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 9789b93e..20494f33 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -30,7 +30,7 @@ A **daily schedule** runs the same comparison, so a lost dispatch event delays a [`prisma/cloud-deploy-action`](https://github.com/prisma/cloud-deploy-action) runs `prisma deploy` with arguments it builds itself. When `prisma@8.0.0-rc.30` renamed `--stage` to `--environment`, every user's preview deploy failed for a week, because nothing here ran the action's arguments. Two checks now run the action's own test against this CLI, both through [`scripts/check-cloud-deploy-action.mjs`](../../scripts/check-cloud-deploy-action.mjs): - **The pull request check.** The required `Test` check in [`pr-quality.yml`](../../.github/workflows/pr-quality.yml) builds `prisma` from the pull request and runs the test against it. That CLI uses the products' released versions, which is what the next release ships. A CLI the released action cannot drive cannot merge, so it cannot be released. -- **The dev-build check.** [`check-dev-build-with-cloud-deploy-action.yml`](../../.github/workflows/check-dev-build-with-cloud-deploy-action.yml) runs after each publish from `main`, installs the dev build that run published, and runs the test against it. That CLI uses the products' dev builds, which is what a later release will ship. It runs at the next merge to this repository's `main` after a product publishes a dev build, not at the moment the product publishes. It never holds or fails the publish. On any failure it posts to Slack through the `SLACK_WEBHOOK_URL` secret, and the message says whether the action cannot drive the dev build or the check itself could not run. Every run checks the secret in its first step and fails if it is not set. +- **The dev-build check.** [`check-dev-build-with-cloud-deploy-action.yml`](../../.github/workflows/check-dev-build-with-cloud-deploy-action.yml) runs after each publish from `main`, installs the dev build that run published, and runs the test against it. That CLI uses the products' dev builds, which is what a later release will ship. It runs at the next merge to this repository's `main` after a product publishes a dev build, not at the moment the product publishes. It never holds or fails the publish. On any failure it posts to Slack through the `SLACK_WEBHOOK_URL` secret. The message comes from the script's exit code: 1 means the action's test ran and the action cannot drive the dev build; 2, or a failure in an earlier step, means the check itself could not run. Every run checks the secret in its first step and fails if it is not set. The pull request check is part of the `Test` job because that check is already required on `main`. It should move to its own required job the next time the `main` ruleset is changed. @@ -38,7 +38,7 @@ The pull request check is part of the `Test` job because that check is already r - The test is `tests/prisma-cli.test.mjs`, and it needs no install: it imports only `../cli.mjs` and Node built-ins. - The test reads the executable to test from the `PRISMA_CLI_BINS` environment variable. -- The script fails unless the two deploy cases (`... accepts the deploy arguments for production` and for a named environment) ran and passed. Without an executable the test runs no cases and passes, so a renamed variable would otherwise go unnoticed. The destroy case may be skipped, because CLIs without a `destroy` command skip it. +- The script finds the two deploy cases by their titles (`... accepts the deploy arguments for production` and for a named environment) and exits 2 unless both ran. Without an executable the test runs no cases and passes, so a renamed variable or renamed titles would otherwise go unnoticed. Any failed case makes it exit 1. The destroy case may be skipped, because CLIs without a `destroy` command skip it. - The test reads this CLI's error codes: `CLI.INVALID_ARGUMENTS`, `CLI.COMMAND_MOVED` or `CLI.UNKNOWN_COMMAND` for rejected arguments, and `CLI.CREDENTIALS_REQUIRED` or `CLI.CONFIG_SECTION_INVALID` as the first check after the arguments are parsed. Both checks use the action at `v1`, its moving release tag, which is what users run. The repository variable `CLOUD_DEPLOY_ACTION_REF` replaces `v1` in both. diff --git a/scripts/check-cloud-deploy-action-utils.mjs b/scripts/check-cloud-deploy-action-utils.mjs new file mode 100644 index 00000000..57bdfe4f --- /dev/null +++ b/scripts/check-cloud-deploy-action-utils.mjs @@ -0,0 +1,40 @@ +const DEPLOY_CASE = /accepts the deploy arguments for (.+)$/; + +/** The test ran and the action cannot drive the CLI. */ +export const EXIT_INCOMPATIBLE = 1; +/** The check could not run, so it says nothing about the CLI. */ +export const EXIT_NOT_RUN = 2; + +/** + * Judges a finished run of the action's test. `incompatible` means a case + * failed; `not-run` means a required deploy case is missing from the run. + * + * @param {readonly { name: string, outcome: "pass" | "fail" | "skip" }[]} results + * @returns {{ verdict: "pass" | "incompatible" | "not-run", problems: string[] }} + */ +export function judgeRun(results) { + const problems = results + .filter((result) => result.outcome === "fail") + .map((result) => `Failed: ${result.name}`); + const ranDeployTargets = results + .filter((result) => result.outcome !== "skip") + .map((result) => DEPLOY_CASE.exec(result.name)?.[1]) + .filter((target) => target !== undefined); + const missing = []; + if (!ranDeployTargets.includes("production")) { + missing.push('"... accepts the deploy arguments for production"'); + } + if (!ranDeployTargets.some((target) => target !== "production")) { + missing.push( + '"... accepts the deploy arguments for ", with an environment other than production', + ); + } + for (const title of missing) { + problems.push( + `No test titled ${title} ran. This script finds the action's deploy cases by these titles, so the action's test titles may have changed. See docs/oss/release-automation.md.`, + ); + } + if (missing.length > 0) return { verdict: "not-run", problems }; + if (problems.length > 0) return { verdict: "incompatible", problems }; + return { verdict: "pass", problems }; +} diff --git a/scripts/check-cloud-deploy-action.mjs b/scripts/check-cloud-deploy-action.mjs index 2c0c1902..0512b774 100644 --- a/scripts/check-cloud-deploy-action.mjs +++ b/scripts/check-cloud-deploy-action.mjs @@ -3,7 +3,10 @@ // Runs prisma/cloud-deploy-action's own CLI test against one `prisma` // executable. The test passes with zero cases when it gets no executable // (for example after a rename of PRISMA_CLI_BINS in the action), so this -// also requires the deploy cases to have run and passed. +// also requires the deploy cases to have run. +// +// Exit codes: 0 the action can drive the executable, 1 it cannot, +// 2 the check could not run. // // Usage: node scripts/check-cloud-deploy-action.mjs @@ -11,35 +14,13 @@ import { accessSync, constants, existsSync, statSync } from "node:fs"; import { join, resolve } from "node:path"; import { run } from "node:test"; import { spec } from "node:test/reporters"; -import { pathToFileURL } from "node:url"; +import { + EXIT_INCOMPATIBLE, + EXIT_NOT_RUN, + judgeRun, +} from "./check-cloud-deploy-action-utils.mjs"; const TEST_FILE = "tests/prisma-cli.test.mjs"; -const DEPLOY_CASE = /accepts the deploy arguments for (.+)$/; - -/** - * Problems with a finished test run, or none when it counts as a pass. - * - * @param {readonly { name: string, outcome: "pass" | "fail" | "skip" }[]} results - * @returns {string[]} - */ -export function findProblems(results) { - const problems = results - .filter((result) => result.outcome === "fail") - .map((result) => `Failed: ${result.name}`); - const passedDeployTargets = results - .filter((result) => result.outcome === "pass") - .map((result) => DEPLOY_CASE.exec(result.name)?.[1]) - .filter((target) => target !== undefined); - if (!passedDeployTargets.includes("production")) { - problems.push("The deploy case for production did not run and pass."); - } - if (!passedDeployTargets.some((target) => target !== "production")) { - problems.push( - "The deploy case for a named environment did not run and pass.", - ); - } - return problems; -} function isExecutableFile(path) { try { @@ -56,21 +37,21 @@ async function main() { console.error( "Usage: node scripts/check-cloud-deploy-action.mjs ", ); - process.exit(1); + process.exit(EXIT_NOT_RUN); } const testFile = resolve(actionDir, TEST_FILE); if (!existsSync(testFile)) { console.error( - `::error::${join(actionDir, TEST_FILE)} does not exist. prisma/cloud-deploy-action must keep its CLI test at this path.`, + `::error::${join(actionDir, TEST_FILE)} does not exist. prisma/cloud-deploy-action must keep its CLI test at this path. The check could not run.`, ); - process.exit(1); + process.exit(EXIT_NOT_RUN); } const executable = resolve(bin); if (!isExecutableFile(executable)) { console.error( - `::error::The prisma executable ${executable} is missing or not executable.`, + `::error::The prisma executable ${executable} is missing or not executable. The check could not run.`, ); - process.exit(1); + process.exit(EXIT_NOT_RUN); } process.env.PRISMA_CLI_BINS = executable; @@ -87,22 +68,25 @@ async function main() { process.stdout.write(chunk); } - const problems = findProblems(results); - if (problems.length > 0) { - for (const problem of problems) { - console.error(`::error::${problem}`); - } + const { verdict, problems } = judgeRun(results); + for (const problem of problems) { + console.error(`::error::${problem}`); + } + if (verdict === "not-run") { + console.error( + `::error::The check could not run: prisma/cloud-deploy-action's deploy cases did not run against ${executable}.`, + ); + process.exit(EXIT_NOT_RUN); + } + if (verdict === "incompatible") { console.error( - `::error::prisma/cloud-deploy-action's test did not pass against ${executable}.`, + `::error::prisma/cloud-deploy-action cannot drive ${executable}: its test failed.`, ); - process.exit(1); + process.exit(EXIT_INCOMPATIBLE); } console.log( `prisma/cloud-deploy-action's test passes against ${executable}.`, ); } -const isDirectRun = - process.argv[1] !== undefined && - import.meta.url === pathToFileURL(process.argv[1]).href; -if (isDirectRun) await main(); +await main(); diff --git a/scripts/check-cloud-deploy-action.test.mjs b/scripts/check-cloud-deploy-action.test.mjs index b74bb4b0..362bb416 100644 --- a/scripts/check-cloud-deploy-action.test.mjs +++ b/scripts/check-cloud-deploy-action.test.mjs @@ -1,49 +1,114 @@ import assert from "node:assert/strict"; -import { describe, it } from "node:test"; -import { findProblems } from "./check-cloud-deploy-action.mjs"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, rmSync, symlinkSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { after, describe, it } from "node:test"; +import { fileURLToPath } from "node:url"; +import { judgeRun } from "./check-cloud-deploy-action-utils.mjs"; const production = "prisma 8.0.0 accepts the deploy arguments for production"; const named = "prisma 8.0.0 accepts the deploy arguments for pr-7"; const destroy = "prisma 8.0.0 accepts the destroy arguments"; -describe("findProblems", () => { +describe("judgeRun", () => { it("passes when both deploy cases pass and the destroy case is skipped", () => { assert.deepEqual( - findProblems([ + judgeRun([ { name: production, outcome: "pass" }, { name: named, outcome: "pass" }, { name: destroy, outcome: "skip" }, ]), - [], + { verdict: "pass", problems: [] }, ); }); - it("fails a run with no cases, as when the action renames PRISMA_CLI_BINS", () => { - assert.equal( - findProblems([{ name: "tests/prisma-cli.test.mjs", outcome: "pass" }]) - .length, - 2, + it("reports a run with no cases as not run, as when the action renames PRISMA_CLI_BINS", () => { + const { verdict, problems } = judgeRun([ + { name: "tests/prisma-cli.test.mjs", outcome: "pass" }, + ]); + assert.equal(verdict, "not-run"); + assert.equal(problems.length, 2); + assert.ok( + problems[0].includes("accepts the deploy arguments for production"), ); + assert.ok(problems[0].includes("test titles may have changed")); }); - it("fails when a deploy case is skipped instead of passing", () => { + it("reports a skipped deploy case as not run", () => { + const { verdict, problems } = judgeRun([ + { name: production, outcome: "pass" }, + { name: named, outcome: "skip" }, + ]); + assert.equal(verdict, "not-run"); + assert.ok(problems[0].includes("")); + }); + + it("reports a failed deploy case as incompatible", () => { assert.deepEqual( - findProblems([ - { name: production, outcome: "pass" }, - { name: named, outcome: "skip" }, + judgeRun([ + { name: production, outcome: "fail" }, + { name: named, outcome: "pass" }, ]), - ["The deploy case for a named environment did not run and pass."], + { verdict: "incompatible", problems: [`Failed: ${production}`] }, ); }); - it("fails on any failed case", () => { + it("reports any other failed case as incompatible", () => { assert.deepEqual( - findProblems([ + judgeRun([ { name: production, outcome: "pass" }, { name: named, outcome: "pass" }, { name: destroy, outcome: "fail" }, ]), - [`Failed: ${destroy}`], + { verdict: "incompatible", problems: [`Failed: ${destroy}`] }, + ); + }); +}); + +describe("check-cloud-deploy-action.mjs", () => { + const scripts = dirname(fileURLToPath(import.meta.url)); + const actionDir = join(scripts, "fixtures/cloud-deploy-action"); + const rejecting = join(scripts, "fixtures/rejecting-prisma"); + const accepting = join(scripts, "fixtures/accepting-prisma"); + const linkRoot = mkdtempSync(join(tmpdir(), "check-cloud-deploy-action-")); + after(() => rmSync(linkRoot, { recursive: true, force: true })); + + // Inside `node --test`, run() in the child would otherwise skip its files. + const { NODE_TEST_CONTEXT: _, ...env } = process.env; + + function check(script, bin) { + return spawnSync(process.execPath, [script, actionDir, bin], { + encoding: "utf8", + env, + }); + } + + const script = join(scripts, "check-cloud-deploy-action.mjs"); + + it("exits 0 for a CLI that accepts the arguments", () => { + const result = check(script, accepting); + assert.equal(result.status, 0, result.stderr); + }); + + it("exits 1 for a CLI that rejects the arguments", () => { + const result = check(script, rejecting); + assert.equal(result.status, 1, result.stderr); + assert.ok(result.stderr.includes("cannot drive")); + }); + + it("exits 2 when the executable is missing", () => { + const result = check(script, join(scripts, "fixtures/no-such-prisma")); + assert.equal(result.status, 2, result.stderr); + }); + + it("runs when started through a symbolic link", () => { + const linked = join(linkRoot, "scripts"); + symlinkSync(scripts, linked); + const result = check( + join(linked, "check-cloud-deploy-action.mjs"), + rejecting, ); + assert.equal(result.status, 1, result.stderr); }); }); diff --git a/scripts/fixtures/accepting-prisma b/scripts/fixtures/accepting-prisma new file mode 100755 index 00000000..4d60ecce --- /dev/null +++ b/scripts/fixtures/accepting-prisma @@ -0,0 +1,2 @@ +#!/usr/bin/env node +console.log(process.argv[2] === "--version" ? "8.0.0" : "CLI.CREDENTIALS_REQUIRED"); diff --git a/scripts/fixtures/cloud-deploy-action/tests/prisma-cli.test.mjs b/scripts/fixtures/cloud-deploy-action/tests/prisma-cli.test.mjs new file mode 100644 index 00000000..89333bff --- /dev/null +++ b/scripts/fixtures/cloud-deploy-action/tests/prisma-cli.test.mjs @@ -0,0 +1,25 @@ +// A small stand-in for prisma/cloud-deploy-action's tests/prisma-cli.test.mjs +// with the same contract: PRISMA_CLI_BINS and the deploy case titles. +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { test } from "node:test"; + +const REJECTED_ARGUMENTS = /CLI\.INVALID_ARGUMENTS/; +const bins = (process.env.PRISMA_CLI_BINS ?? "").split(",").filter(Boolean); + +for (const bin of bins) { + const version = spawnSync(bin, ["--version"], { + encoding: "utf8", + }).stdout.trim(); + for (const environment of ["", "pr-7"]) { + test(`prisma ${version} accepts the deploy arguments for ${environment || "production"}`, () => { + const args = [ + "deploy", + "module.ts", + ...(environment ? ["--environment", environment] : []), + ]; + const { stdout } = spawnSync(bin, args, { encoding: "utf8" }); + assert.doesNotMatch(stdout, REJECTED_ARGUMENTS); + }); + } +} diff --git a/scripts/fixtures/rejecting-prisma b/scripts/fixtures/rejecting-prisma new file mode 100755 index 00000000..8a5d79f9 --- /dev/null +++ b/scripts/fixtures/rejecting-prisma @@ -0,0 +1,2 @@ +#!/usr/bin/env node +console.log(process.argv[2] === "--version" ? "8.0.0" : "CLI.INVALID_ARGUMENTS"); From 1cb7dc836f404cee971e7cc7bfb9a4288673b740 Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 17 Nov 2026 07:54:58 +1100 Subject: [PATCH 4/5] ci: report a published dev build that left no version artifact, whatever started the publish The dev-build check treated a missing artifact as an error only for push runs. A manual publish whose upload failed was skipped without an alert. It now reads the result of the publish step itself, so any run that published is checked or reported. Co-Authored-By: Claude Fable 5.2 Signed-off-by: willbot Signed-off-by: Will Madden --- .../check-dev-build-with-cloud-deploy-action.yml | 10 +++++----- .github/workflows/publish.yml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-dev-build-with-cloud-deploy-action.yml b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml index 3ef8e3ae..ea6d0b94 100644 --- a/.github/workflows/check-dev-build-with-cloud-deploy-action.yml +++ b/.github/workflows/check-dev-build-with-cloud-deploy-action.yml @@ -41,17 +41,17 @@ jobs: env: GH_TOKEN: ${{ github.token }} PUBLISH_RUN_ID: ${{ github.event.workflow_run.id }} - PUBLISH_EVENT: ${{ github.event.workflow_run.event }} - PUBLISH_CONCLUSION: ${{ github.event.workflow_run.conclusion }} run: | artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/artifacts" \ --jq '.artifacts[] | select(.name == "published-dev-version") | .id') if [ -z "$artifact" ]; then - if [ "$PUBLISH_EVENT" = push ] && [ "$PUBLISH_CONCLUSION" = success ]; then - echo "::error::Publish run $PUBLISH_RUN_ID succeeded on a push but has no published-dev-version artifact." + published=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/jobs" \ + --jq '[.jobs[].steps[] | select(.name == "Publish the dev version")] | first | .conclusion') + if [ "$published" = success ]; then + echo "::error::Publish run $PUBLISH_RUN_ID published a dev build but has no published-dev-version artifact." exit 1 fi - echo "Publish run $PUBLISH_RUN_ID ($PUBLISH_EVENT, $PUBLISH_CONCLUSION) published no dev build. Nothing to check." + echo "Publish run $PUBLISH_RUN_ID published no dev build (its publish step: ${published:-absent}). Nothing to check." exit 0 fi gh run download "$PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --name published-dev-version --dir "$RUNNER_TEMP/published-dev-version" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 50c4612c..c813f864 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -104,6 +104,7 @@ jobs: NPM_CONFIG_PROVENANCE: "true" run: bash scripts/publish-packages.sh latest @prisma/cli-engine + # check-dev-build-with-cloud-deploy-action.yml reads this step's result by its name. - name: Publish the dev version if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }} env: From cdec6d9c69e5922f9cfb39e2f4aa0f3cabf87977 Mon Sep 17 00:00:00 2001 From: willbot Date: Mon, 23 Nov 2026 08:06:38 +1100 Subject: [PATCH 5/5] ci: report a crash of the cloud-deploy-action check as a check that could not run An unexpected error exited with Node's default code 1, which this script uses for an incompatible CLI, so the dev-build alert would have blamed the action. The docs now also name the version output the action's test relies on, and link the follow-up issue. Co-Authored-By: Claude Fable 5.2 Signed-off-by: willbot Signed-off-by: Will Madden --- docs/oss/release-automation.md | 3 ++- scripts/check-cloud-deploy-action-utils.mjs | 17 +++++++++++++++++ scripts/check-cloud-deploy-action.mjs | 14 ++++++++------ scripts/check-cloud-deploy-action.test.mjs | 15 ++++++++++++++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 20494f33..81bc3869 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -38,6 +38,7 @@ The pull request check is part of the `Test` job because that check is already r - The test is `tests/prisma-cli.test.mjs`, and it needs no install: it imports only `../cli.mjs` and Node built-ins. - The test reads the executable to test from the `PRISMA_CLI_BINS` environment variable. +- The test reads the CLI's version from the output of `prisma --version`, which must start with the version number. - The script finds the two deploy cases by their titles (`... accepts the deploy arguments for production` and for a named environment) and exits 2 unless both ran. Without an executable the test runs no cases and passes, so a renamed variable or renamed titles would otherwise go unnoticed. Any failed case makes it exit 1. The destroy case may be skipped, because CLIs without a `destroy` command skip it. - The test reads this CLI's error codes: `CLI.INVALID_ARGUMENTS`, `CLI.COMMAND_MOVED` or `CLI.UNKNOWN_COMMAND` for rejected arguments, and `CLI.CREDENTIALS_REQUIRED` or `CLI.CONFIG_SECTION_INVALID` as the first check after the arguments are parsed. @@ -55,7 +56,7 @@ When a product changes the arguments: When the change is made in this repository itself, the pull request's CLI reports the last release's version, so the action sends it the old arguments and the check fails. Release the action first with a rule for the next version, and bump the version (`pnpm bump-version`) in the same pull request. -Making the action detect the arguments without relying on the version number is tracked as follow-up in `prisma/cloud-deploy-action`. +Making the action detect the arguments without relying on the version number is tracked in [prisma/cloud-deploy-action#27](https://github.com/prisma/cloud-deploy-action/issues/27). ## The shared secret: `DEPLOY_GITHUB_TOKEN` diff --git a/scripts/check-cloud-deploy-action-utils.mjs b/scripts/check-cloud-deploy-action-utils.mjs index 57bdfe4f..1735c031 100644 --- a/scripts/check-cloud-deploy-action-utils.mjs +++ b/scripts/check-cloud-deploy-action-utils.mjs @@ -38,3 +38,20 @@ export function judgeRun(results) { if (problems.length > 0) return { verdict: "incompatible", problems }; return { verdict: "pass", problems }; } + +/** + * A crash of the check is not a verdict on the CLI, so it must not exit + * with Node's default 1, which means "incompatible" here. + * + * @param {() => Promise} main + */ +export async function exitCodeOf(main) { + try { + return await main(); + } catch (error) { + console.error( + `::error::The check could not run: ${error instanceof Error ? error.stack : error}`, + ); + return EXIT_NOT_RUN; + } +} diff --git a/scripts/check-cloud-deploy-action.mjs b/scripts/check-cloud-deploy-action.mjs index 0512b774..322133ea 100644 --- a/scripts/check-cloud-deploy-action.mjs +++ b/scripts/check-cloud-deploy-action.mjs @@ -17,6 +17,7 @@ import { spec } from "node:test/reporters"; import { EXIT_INCOMPATIBLE, EXIT_NOT_RUN, + exitCodeOf, judgeRun, } from "./check-cloud-deploy-action-utils.mjs"; @@ -37,21 +38,21 @@ async function main() { console.error( "Usage: node scripts/check-cloud-deploy-action.mjs ", ); - process.exit(EXIT_NOT_RUN); + return EXIT_NOT_RUN; } const testFile = resolve(actionDir, TEST_FILE); if (!existsSync(testFile)) { console.error( `::error::${join(actionDir, TEST_FILE)} does not exist. prisma/cloud-deploy-action must keep its CLI test at this path. The check could not run.`, ); - process.exit(EXIT_NOT_RUN); + return EXIT_NOT_RUN; } const executable = resolve(bin); if (!isExecutableFile(executable)) { console.error( `::error::The prisma executable ${executable} is missing or not executable. The check could not run.`, ); - process.exit(EXIT_NOT_RUN); + return EXIT_NOT_RUN; } process.env.PRISMA_CLI_BINS = executable; @@ -76,17 +77,18 @@ async function main() { console.error( `::error::The check could not run: prisma/cloud-deploy-action's deploy cases did not run against ${executable}.`, ); - process.exit(EXIT_NOT_RUN); + return EXIT_NOT_RUN; } if (verdict === "incompatible") { console.error( `::error::prisma/cloud-deploy-action cannot drive ${executable}: its test failed.`, ); - process.exit(EXIT_INCOMPATIBLE); + return EXIT_INCOMPATIBLE; } console.log( `prisma/cloud-deploy-action's test passes against ${executable}.`, ); + return 0; } -await main(); +process.exit(await exitCodeOf(main)); diff --git a/scripts/check-cloud-deploy-action.test.mjs b/scripts/check-cloud-deploy-action.test.mjs index 362bb416..e9d8881c 100644 --- a/scripts/check-cloud-deploy-action.test.mjs +++ b/scripts/check-cloud-deploy-action.test.mjs @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { after, describe, it } from "node:test"; import { fileURLToPath } from "node:url"; -import { judgeRun } from "./check-cloud-deploy-action-utils.mjs"; +import { exitCodeOf, judgeRun } from "./check-cloud-deploy-action-utils.mjs"; const production = "prisma 8.0.0 accepts the deploy arguments for production"; const named = "prisma 8.0.0 accepts the deploy arguments for pr-7"; @@ -66,6 +66,19 @@ describe("judgeRun", () => { }); }); +describe("exitCodeOf", () => { + it("returns what the check returns", async () => { + assert.equal(await exitCodeOf(async () => 1), 1); + }); + + it("reports a crash as a check that could not run", async () => { + const crash = async () => { + throw new Error("boom"); + }; + assert.equal(await exitCodeOf(crash), 2); + }); +}); + describe("check-cloud-deploy-action.mjs", () => { const scripts = dirname(fileURLToPath(import.meta.url)); const actionDir = join(scripts, "fixtures/cloud-deploy-action");