Skip to content

Commit 097252c

Browse files
authored
ref(core): Replace release detection with Sentry CLI release detection (#87)
Remove our previous release detection code (RIP) and replace it with CLI functionality. Doing this to ensure feature parity with the CLI, we can revisit this if we have time
1 parent 4b7d2e8 commit 097252c

File tree

7 files changed

+20
-136
lines changed

7 files changed

+20
-136
lines changed

packages/bundler-plugin-core/src/detect-release.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

packages/bundler-plugin-core/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { addSpanToTransaction, captureMinimalError, makeSentryClient } from "./s
1414
import { Span, Transaction } from "@sentry/types";
1515
import { createLogger } from "./sentry/logger";
1616
import { normalizeUserOptions } from "./options-mapping";
17+
import { getSentryCli } from "./sentry/cli";
1718

1819
// We prefix the polyfill id with \0 to tell other plugins not to try to load or transform it.
1920
// This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
@@ -87,6 +88,8 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
8788
silent: internalOptions.silent,
8889
});
8990

91+
const cli = getSentryCli(internalOptions, logger);
92+
9093
if (internalOptions.telemetry) {
9194
logger.info("Sending error and performance telemetry data to Sentry.");
9295
logger.info("To disable telemetry, set `options.telemetry` to `false`.");
@@ -116,13 +119,17 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
116119
/**
117120
* Responsible for starting the plugin execution transaction and the release injection span
118121
*/
119-
buildStart() {
122+
async buildStart() {
123+
if (!internalOptions.release) {
124+
internalOptions.release = await cli.releases.proposeVersion();
125+
}
126+
120127
transaction = sentryHub.startTransaction({
121128
op: "function.plugin",
122129
name: "Sentry Bundler Plugin execution",
123130
});
124131
releaseInjectionSpan = addSpanToTransaction(
125-
{ hub: sentryHub, parentSpan: transaction, logger },
132+
{ hub: sentryHub, parentSpan: transaction, logger, cli },
126133
"function.plugin.inject_release",
127134
"Release injection"
128135
);
@@ -259,7 +266,7 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
259266
const releasePipelineSpan =
260267
transaction &&
261268
addSpanToTransaction(
262-
{ hub: sentryHub, parentSpan: transaction, logger },
269+
{ hub: sentryHub, parentSpan: transaction, logger, cli },
263270
"function.plugin.release",
264271
"Release pipeline"
265272
);
@@ -275,7 +282,7 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
275282
// That's good for them but a hassle for us. Let's try to normalize this into one data type
276283
// (I vote IncludeEntry[]) and continue with that down the line
277284

278-
const ctx: BuildContext = { hub: sentryHub, parentSpan: releasePipelineSpan, logger };
285+
const ctx: BuildContext = { hub: sentryHub, parentSpan: releasePipelineSpan, logger, cli };
279286

280287
createNewRelease(internalOptions, ctx)
281288
.then(() => cleanArtifacts(internalOptions, ctx))

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { detectRelease } from "./detect-release";
21
import { IncludeEntry as UserIncludeEntry, Options as UserOptions } from "./types";
32

43
type RequiredInternalOptions = Required<
@@ -81,7 +80,7 @@ export function normalizeUserOptions(userOptions: UserOptions): InternalOptions
8180
project: userOptions.project,
8281
authToken: userOptions.authToken,
8382
url: userOptions.url ?? "https://sentry.io/",
84-
release: userOptions.release ?? detectRelease(),
83+
release: userOptions.release ?? "",
8584
finalize: userOptions.finalize ?? true,
8685
validate: userOptions.validate ?? false,
8786
vcsRemote: userOptions.vcsRemote ?? "origin",

packages/bundler-plugin-core/src/sentry/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InternalOptions } from "../options-mapping";
33
import { Logger } from "./logger";
44

55
type SentryDryRunCLI = { releases: Omit<SentryCliReleases, "listDeploys" | "execute"> };
6-
type SentryCLILike = SentryCli | SentryDryRunCLI;
6+
export type SentryCLILike = SentryCli | SentryDryRunCLI;
77

88
/**
99
* Creates a new Sentry CLI instance.
@@ -22,6 +22,7 @@ export function getSentryCli(internalOptions: InternalOptions, logger: Logger):
2222
});
2323

2424
if (internalOptions.dryRun) {
25+
logger.info("In DRY RUN Mode");
2526
return getDryRunCLI(cli, logger);
2627
}
2728

packages/bundler-plugin-core/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Hub } from "@sentry/hub";
22
import { Span } from "@sentry/tracing";
3+
import { SentryCLILike } from "./sentry/cli";
34
import { createLogger } from "./sentry/logger";
45

56
/**
@@ -348,4 +349,5 @@ export type BuildContext = {
348349
hub: Hub;
349350
parentSpan?: Span;
350351
logger: ReturnType<typeof createLogger>;
352+
cli: SentryCLILike;
351353
};

packages/bundler-plugin-core/test/cli.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ describe("getSentryCLI", () => {
88
expect(cli).toBeInstanceOf(SentryCli);
99
});
1010

11-
it("returns a valid CLI instance if dryRun is set to true", () => {
11+
it("returns a dry run CLI stub if `dryRun` is set to true", () => {
12+
const logger = { info: jest.fn() };
1213
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
13-
const cli = getSentryCli({ dryRun: true } as any, {} as any);
14+
const cli = getSentryCli({ dryRun: true } as any, logger as any);
15+
expect(logger.info).toHaveBeenCalledWith(expect.stringMatching("DRY RUN"));
1416
expect(cli).not.toBeInstanceOf(SentryCli);
1517
});
1618
});

packages/bundler-plugin-core/test/getReleaseName.test.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)