From 2e743b8eca5e026605580f8c865f9741f40a7526 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 11:17:29 +0000 Subject: [PATCH] fix(cli): Drop head -n 1 from the wrangler wizard's release version sentry release propose-version now prints its hint on stderr when stdout is piped (getsentry/toolkit#2594), so the generated scripts capture the version directly. Without the pipe, a failing propose-version no longer has its exit code hidden by head. --- .../lib/wizard/sourcemaps/tools/wrangler.ts | 10 ++-- .../wizard/sourcemaps/tools/wrangler.test.ts | 46 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts b/packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts index 43b3d8254..4bc147e83 100644 --- a/packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts +++ b/packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts @@ -133,12 +133,11 @@ async function createAndAddSentrySourcemapsScript( } /** - * Prints the proposed release version. `sentry release propose-version` - * prints a hint after the version when its output is piped, so only the - * first line is kept. + * Prints the proposed release version. When captured, stdout holds only the + * version: the command's hint goes to stderr (getsentry/toolkit#2531). */ // oxlint-disable-next-line sentry-cli/no-hardcoded-sentry-command -- runs the project's installed `sentry` package from its package.json scripts, not a hint -const PROPOSE_VERSION = "$(sentry release propose-version | head -n 1)"; +const PROPOSE_VERSION = "$(sentry release propose-version)"; /** * The `sentry:sourcemaps` script: create the release and upload the deploy @@ -438,8 +437,7 @@ const COMMAND_SEPARATORS = ["&&", "||", ">>", ">", "<", "|", ";"]; /** * Split a package script into its individual commands at the operators in * {@link COMMAND_SEPARATORS}. Operators inside quotes or a `$(…)` command - * substitution (such as the `| head -n 1` of the release version this - * wizard adds) don't split. The commands are substrings of `script`. + * substitution don't split. The commands are substrings of `script`. */ function splitShellCommands(script: string): string[] { const commands: string[] = []; diff --git a/packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts b/packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts index a0824dc86..b15e997e8 100644 --- a/packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts +++ b/packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts @@ -45,7 +45,7 @@ describe("getSentryCliCommand", () => { it("reads the org and project from .sentryclirc instead of flags", () => { expect(getSentryCliCommand("dist")).toBe( - '_SENTRY_RELEASE=$(sentry release propose-version | head -n 1) && sentry release create "$_SENTRY_RELEASE" && sentry sourcemap upload --release="$_SENTRY_RELEASE" --no-rewrite \'dist\'', + '_SENTRY_RELEASE=$(sentry release propose-version) && sentry release create "$_SENTRY_RELEASE" && sentry sourcemap upload --release="$_SENTRY_RELEASE" --no-rewrite \'dist\'', ); }); }); @@ -58,7 +58,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - "wrangler deploy --outdir 'dist' --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)", + "wrangler deploy --outdir 'dist' --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version)", ); }); @@ -73,7 +73,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - `wrangler deploy ${arg} --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)`, + `wrangler deploy ${arg} --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version)`, ); }); @@ -90,7 +90,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - `wrangler deploy ${arg} --outdir 'dist' --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)`, + `wrangler deploy ${arg} --outdir 'dist' --var SENTRY_RELEASE:$(sentry release propose-version)`, ); }); @@ -101,7 +101,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - "precheck && wrangler deploy --outdir dist --upload-source-maps --var SOMEVAR:someValue --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1) && postcheck", + "precheck && wrangler deploy --outdir dist --upload-source-maps --var SOMEVAR:someValue --var SENTRY_RELEASE:$(sentry release propose-version) && postcheck", ); }); @@ -112,7 +112,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - "wrangler whoami && wrangler deploy --outdir dist --upload-source-maps --var SOMEVAR:someValue --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1) && wrangler someothercommand", + "wrangler whoami && wrangler deploy --outdir dist --upload-source-maps --var SOMEVAR:someValue --var SENTRY_RELEASE:$(sentry release propose-version) && wrangler someothercommand", ); }); @@ -123,7 +123,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - "wrangler --version --env production deploy --outdir someplace --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)", + "wrangler --version --env production deploy --outdir someplace --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version)", ); }); @@ -134,7 +134,7 @@ describe("safeInsertArgsToWranglerDeployCommand", () => { ); expect(newCommand).toBe( - "notwrangler --version deploy && wrangler --version --env whoami && wrangler --version --env production deploy --outdir someplace --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)", + "notwrangler --version deploy && wrangler --version --env whoami && wrangler --version --env production deploy --outdir someplace --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version)", ); }); @@ -209,16 +209,13 @@ describe("getWranglerDeployCommand", () => { expect(deployCommand).toBe("wrangler deploy --outdir someplace"); }); - it("keeps the release version pipe inside the deploy command", () => { - const deployCommand = safeInsertArgsToWranglerDeployCommand( - "wrangler deploy && postcheck", - "dist", + it("keeps a pipe inside a command substitution in the deploy command", () => { + const deployCommand = getWranglerDeployCommand( + "wrangler deploy --var VERSION:$(git rev-parse HEAD | cut -c1-7) && postcheck", ); - const rerunDeployCommand = getWranglerDeployCommand(deployCommand ?? ""); - - expect(rerunDeployCommand?.replace(/\s+/g, " ").trim()).toBe( - "wrangler deploy --outdir 'dist' --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)", + expect(deployCommand?.trim()).toBe( + "wrangler deploy --var VERSION:$(git rev-parse HEAD | cut -c1-7)", ); }); @@ -249,19 +246,26 @@ describe("getWranglerDeployCommand", () => { // Print the release and upload arguments instead of running the Sentry CLI. // The `sentry` shell function shadows any `sentry` binary on PATH, so the -// script never reaches Sentry. `propose-version` prints a hint after the -// version, as `sentry` does when its output is piped. Command substitution -// payloads use printf so a quoting regression has no filesystem side effects. +// script never reaches Sentry. `propose-version` prints the version on +// stdout and its hint on stderr, as `sentry` does when its output is piped. +// Command substitution payloads use printf so a quoting regression has no +// filesystem side effects. function runSentryCliCommand(command: string): string[] { const script = ` sentry() { case "$1 $2" in - 'release propose-version') printf '%s\\n' 'release with spaces' 'Detected from git HEAD' ;; + 'release propose-version') + printf '%s\\n' 'release with spaces' + printf '%s\\n' 'Detected from git HEAD' >&2 + ;; 'release create' | 'sourcemap upload') printf '%s\\n' "$@" ;; esac } ${command}`; - return execFileSync("/bin/bash", ["-c", script], { encoding: "utf8" }) + return execFileSync("/bin/bash", ["-c", script], { + encoding: "utf8", + stdio: "pipe", + }) .trimEnd() .split("\n"); }