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
10 changes: 4 additions & 6 deletions packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,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
Expand Down Expand Up @@ -502,8 +501,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. Each command is a substring of `script` that
* substitution don't split. Each command is a substring of `script` that
* starts at `start`.
*/
function splitShellCommands(script: string): { start: number; text: string }[] {
Expand Down
48 changes: 26 additions & 22 deletions packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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 --strip-prefix .. \'dist\'',
'_SENTRY_RELEASE=$(sentry release propose-version) && sentry release create "$_SENTRY_RELEASE" && sentry sourcemap upload --release="$_SENTRY_RELEASE" --no-rewrite --strip-prefix .. \'dist\'',
);
});
});
Expand All @@ -73,7 +73,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)",
);
});

Expand All @@ -88,7 +88,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)`,
);
});

Expand All @@ -105,7 +105,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)`,
);
});

Expand All @@ -116,7 +116,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",
);
});

Expand All @@ -127,7 +127,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",
);
});

Expand All @@ -138,7 +138,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)",
);
});

Expand All @@ -149,7 +149,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)",
);
});

Expand Down Expand Up @@ -248,7 +248,7 @@ describe("getWranglerDeployCommand", () => {
])("finds wrangler deploy run through a runner: %s", (command) => {
expect(getWranglerDeployCommand(`tsc && ${command}`)?.trim()).toBe(command);
expect(safeInsertArgsToWranglerDeployCommand(command, "dist")).toBe(
`${command} --outdir 'dist' --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version | head -n 1)`,
`${command} --outdir 'dist' --upload-source-maps --var SENTRY_RELEASE:$(sentry release propose-version)`,
);
});

Expand Down Expand Up @@ -289,16 +289,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)",
);
});

Expand Down Expand Up @@ -329,19 +326,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");
}
Loading