From 988b7bcc16dbd1a44aa53bd834e13fdbf3ccb9a4 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 10:26:02 +0100 Subject: [PATCH 1/7] feat: Default to automatically setting commits on release --- .../src/options-mapping.ts | 5 +++++ .../src/plugins/release-management.ts | 19 ++++++++++++++++--- packages/bundler-plugin-core/src/types.ts | 4 +++- .../test/option-mappings.test.ts | 8 ++++++++ .../src/generate-documentation-table.ts | 3 ++- .../fixtures/telemetry/telemetry.test.ts | 2 +- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/bundler-plugin-core/src/options-mapping.ts b/packages/bundler-plugin-core/src/options-mapping.ts index ba12d3e5..3ed9f978 100644 --- a/packages/bundler-plugin-core/src/options-mapping.ts +++ b/packages/bundler-plugin-core/src/options-mapping.ts @@ -26,6 +26,11 @@ export function normalizeUserOptions(userOptions: UserOptions) { create: userOptions.release?.create ?? true, finalize: userOptions.release?.finalize ?? true, vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin", + setCommits: userOptions.release?.setCommits ?? { + auto: true, + isDefault: true, + repo: undefined, // Just to please type narrowing + }, }, bundleSizeOptimizations: userOptions.bundleSizeOptimizations, reactComponentAnnotation: userOptions.reactComponentAnnotation, diff --git a/packages/bundler-plugin-core/src/plugins/release-management.ts b/packages/bundler-plugin-core/src/plugins/release-management.ts index 8abac956..8603ac76 100644 --- a/packages/bundler-plugin-core/src/plugins/release-management.ts +++ b/packages/bundler-plugin-core/src/plugins/release-management.ts @@ -13,7 +13,7 @@ interface ReleaseManagementPluginOptions { shouldCreateRelease: boolean; shouldFinalizeRelease: boolean; include?: string | IncludeEntry | Array; - setCommitsOption?: SentryCliCommitsOptions; + setCommitsOption: SentryCliCommitsOptions | false | { auto: true; isDefault: true }; deployOptions?: SentryCliNewDeployOptions; dist?: string; handleRecoverableError: HandleRecoverableErrorFn; @@ -37,6 +37,7 @@ interface ReleaseManagementPluginOptions { * Additionally, if legacy upload options are set, it uploads source maps in the legacy (non-debugId) way. */ export function releaseManagementPlugin({ + logger, releaseName, include, dist, @@ -86,8 +87,20 @@ export function releaseManagementPlugin({ }); } - if (setCommitsOption) { - await cliInstance.releases.setCommits(releaseName, setCommitsOption); + if (setCommitsOption !== false) { + try { + await cliInstance.releases.setCommits(releaseName, setCommitsOption); + } catch (e) { + // isDefault being present means that the plugin defaulted to `{ auto: true }` for the setCommitsOptions, meaning that wee should not throw when CLI throws because there is no repo + if (!("isDefault" in setCommitsOption)) { + throw e; + } else { + logger.debug( + "An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):", + e + ); + } + } } if (shouldFinalizeRelease) { diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 61db9049..bc55427e 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -200,8 +200,10 @@ export interface Options { /** * Associates the release with its commits in Sentry. + * + * Defaults to `{ auto: true }`. Set to `false` to disable commit association. */ - setCommits?: SetCommitsOptions; + setCommits?: SetCommitsOptions | false; /** * Adds deployment information to the release in Sentry. diff --git a/packages/bundler-plugin-core/test/option-mappings.test.ts b/packages/bundler-plugin-core/test/option-mappings.test.ts index 54907571..af008ad5 100644 --- a/packages/bundler-plugin-core/test/option-mappings.test.ts +++ b/packages/bundler-plugin-core/test/option-mappings.test.ts @@ -23,6 +23,10 @@ describe("normalizeUserOptions()", () => { create: true, vcsRemote: "origin", uploadLegacySourcemaps: "./out", + setCommits: { + auto: true, + isDefault: true, + }, }, silent: false, telemetry: true, @@ -74,6 +78,10 @@ describe("normalizeUserOptions()", () => { sourceMapReference: false, stripCommonPrefix: true, }, + setCommits: { + auto: true, + isDefault: true, + }, }, silent: false, telemetry: true, diff --git a/packages/dev-utils/src/generate-documentation-table.ts b/packages/dev-utils/src/generate-documentation-table.ts index 1d2f3244..bd522fe7 100644 --- a/packages/dev-utils/src/generate-documentation-table.ts +++ b/packages/dev-utils/src/generate-documentation-table.ts @@ -154,7 +154,8 @@ errorHandler: (err) => { }, { name: "setCommits", - fullDescription: "Option to associate the created release with its commits in Sentry.", + fullDescription: + "Option to associate the created release with its commits in Sentry. Defaults to `{ auto: true }`. Set to `false` to disable.", children: [ { name: "previousCommit", diff --git a/packages/integration-tests/fixtures/telemetry/telemetry.test.ts b/packages/integration-tests/fixtures/telemetry/telemetry.test.ts index 5015cfdf..deb289e1 100644 --- a/packages/integration-tests/fixtures/telemetry/telemetry.test.ts +++ b/packages/integration-tests/fixtures/telemetry/telemetry.test.ts @@ -101,7 +101,7 @@ test("rollup bundle telemetry", async () => { "upload-legacy-sourcemaps": false, "module-metadata": false, "inject-build-information": false, - "set-commits": "undefined", + "set-commits": "auto", "finalize-release": true, "deploy-options": false, "custom-error-handler": false, From 62c316c7fd529828104f72e759a842a26183ec8b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 10:50:03 +0100 Subject: [PATCH 2/7] . --- .../bundler-plugin-core/src/options-mapping.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/bundler-plugin-core/src/options-mapping.ts b/packages/bundler-plugin-core/src/options-mapping.ts index 3ed9f978..fbb65695 100644 --- a/packages/bundler-plugin-core/src/options-mapping.ts +++ b/packages/bundler-plugin-core/src/options-mapping.ts @@ -26,11 +26,7 @@ export function normalizeUserOptions(userOptions: UserOptions) { create: userOptions.release?.create ?? true, finalize: userOptions.release?.finalize ?? true, vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin", - setCommits: userOptions.release?.setCommits ?? { - auto: true, - isDefault: true, - repo: undefined, // Just to please type narrowing - }, + setCommits: userOptions.release?.setCommits, }, bundleSizeOptimizations: userOptions.bundleSizeOptimizations, reactComponentAnnotation: userOptions.reactComponentAnnotation, @@ -44,6 +40,14 @@ export function normalizeUserOptions(userOptions: UserOptions) { _experiments: userOptions._experiments ?? {}, }; + if (options.release.setCommits === undefined) { + options.release.setCommits = { + // @ts-expect-error This is fine + auto: true, + isDefault: true, + }; + } + return options; } From 4ddbccb8d44813b8cda875fbf17d7260e753b1e6 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 11:17:43 +0100 Subject: [PATCH 3/7] . --- .../src/options-mapping.ts | 38 +++++++++++++++++-- .../src/plugins/release-management.ts | 4 +- .../test/option-mappings.test.ts | 4 +- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/bundler-plugin-core/src/options-mapping.ts b/packages/bundler-plugin-core/src/options-mapping.ts index fbb65695..c03ae9e2 100644 --- a/packages/bundler-plugin-core/src/options-mapping.ts +++ b/packages/bundler-plugin-core/src/options-mapping.ts @@ -41,10 +41,40 @@ export function normalizeUserOptions(userOptions: UserOptions) { }; if (options.release.setCommits === undefined) { - options.release.setCommits = { - // @ts-expect-error This is fine - auto: true, - isDefault: true, + if ( + process.env["VERCEL"] && + process.env["VERCEL_GIT_COMMIT_SHA"] && + process.env["VERCEL_GIT_REPO_SLUG"] && + process.env["VERCEL_GIT_REPO_OWNER"] + ) { + options.release.setCommits = { + // @ts-expect-error This is fine + shouldNotThrowOnFailure: true, + commit: process.env["VERCEL_GIT_COMMIT_SHA"], + previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"], + repo: `${process.env["VERCEL_GIT_REPO_OWNER"]}/${process.env["VERCEL_GIT_REPO_SLUG"]}`, + ignoreEmpty: true, + ignoreMissing: true, + }; + } else { + options.release.setCommits = { + shouldNotThrowOnFailure: true, + // @ts-expect-error This is fine + auto: true, + ignoreEmpty: true, + ignoreMissing: true, + }; + } + } + + if ( + options.release.deploy === undefined && + process.env["VERCEL"] && + process.env["VERCEL_TARGET_ENV"] + ) { + options.release.deploy = { + env: `vercel-${process.env["VERCEL_TARGET_ENV"]}`, + url: process.env["VERCEL_URL"] ? `https://${process.env["VERCEL_URL"]}` : undefined, }; } diff --git a/packages/bundler-plugin-core/src/plugins/release-management.ts b/packages/bundler-plugin-core/src/plugins/release-management.ts index 8603ac76..6940d530 100644 --- a/packages/bundler-plugin-core/src/plugins/release-management.ts +++ b/packages/bundler-plugin-core/src/plugins/release-management.ts @@ -91,8 +91,8 @@ export function releaseManagementPlugin({ try { await cliInstance.releases.setCommits(releaseName, setCommitsOption); } catch (e) { - // isDefault being present means that the plugin defaulted to `{ auto: true }` for the setCommitsOptions, meaning that wee should not throw when CLI throws because there is no repo - if (!("isDefault" in setCommitsOption)) { + // shouldNotThrowOnFailure being present means that the plugin defaulted to `{ auto: true }` for the setCommitsOptions, meaning that wee should not throw when CLI throws because there is no repo + if (!("shouldNotThrowOnFailure" in setCommitsOption)) { throw e; } else { logger.debug( diff --git a/packages/bundler-plugin-core/test/option-mappings.test.ts b/packages/bundler-plugin-core/test/option-mappings.test.ts index af008ad5..216b7fd2 100644 --- a/packages/bundler-plugin-core/test/option-mappings.test.ts +++ b/packages/bundler-plugin-core/test/option-mappings.test.ts @@ -25,7 +25,7 @@ describe("normalizeUserOptions()", () => { uploadLegacySourcemaps: "./out", setCommits: { auto: true, - isDefault: true, + shouldNotThrowOnFailure: true, }, }, silent: false, @@ -80,7 +80,7 @@ describe("normalizeUserOptions()", () => { }, setCommits: { auto: true, - isDefault: true, + shouldNotThrowOnFailure: true, }, }, silent: false, From 4cf54b743c98134858a1ece0414600b9a3803908 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 13:08:38 +0100 Subject: [PATCH 4/7] . --- packages/bundler-plugin-core/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index 72834e92..a5323f6f 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -370,7 +370,9 @@ export function sentryUnpluginFactory({ shouldCreateRelease: options.release.create, shouldFinalizeRelease: options.release.finalize, include: options.release.uploadLegacySourcemaps, - setCommitsOption: options.release.setCommits, + // setCommits has a default defined by the options mappings + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + setCommitsOption: options.release.setCommits!, deployOptions: options.release.deploy, dist: options.release.dist, handleRecoverableError: handleRecoverableError, From 93871ed7880d12ca47c664822dbe3235a80f7409 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 13:13:27 +0100 Subject: [PATCH 5/7] . --- .../src/plugins/release-management.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/plugins/release-management.ts b/packages/bundler-plugin-core/src/plugins/release-management.ts index 6940d530..fd00157f 100644 --- a/packages/bundler-plugin-core/src/plugins/release-management.ts +++ b/packages/bundler-plugin-core/src/plugins/release-management.ts @@ -92,13 +92,16 @@ export function releaseManagementPlugin({ await cliInstance.releases.setCommits(releaseName, setCommitsOption); } catch (e) { // shouldNotThrowOnFailure being present means that the plugin defaulted to `{ auto: true }` for the setCommitsOptions, meaning that wee should not throw when CLI throws because there is no repo - if (!("shouldNotThrowOnFailure" in setCommitsOption)) { - throw e; - } else { + if ( + "shouldNotThrowOnFailure" in setCommitsOption && + setCommitsOption.shouldNotThrowOnFailure + ) { logger.debug( "An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):", e ); + } else { + throw e; } } } From 1003d162f8aa9b39eae2b6840b06acaf997fff49 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 13:26:02 +0100 Subject: [PATCH 6/7] Fix test --- packages/bundler-plugin-core/test/option-mappings.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/bundler-plugin-core/test/option-mappings.test.ts b/packages/bundler-plugin-core/test/option-mappings.test.ts index 216b7fd2..f233e1e7 100644 --- a/packages/bundler-plugin-core/test/option-mappings.test.ts +++ b/packages/bundler-plugin-core/test/option-mappings.test.ts @@ -26,6 +26,8 @@ describe("normalizeUserOptions()", () => { setCommits: { auto: true, shouldNotThrowOnFailure: true, + ignoreEmpty: true, + ignoreMissing: true, }, }, silent: false, @@ -81,6 +83,8 @@ describe("normalizeUserOptions()", () => { setCommits: { auto: true, shouldNotThrowOnFailure: true, + ignoreEmpty: true, + ignoreMissing: true, }, }, silent: false, From 572c9845aaf330f2b35f083b5259afbd4c1318d6 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Mar 2025 13:58:00 +0100 Subject: [PATCH 7/7] type interface --- packages/bundler-plugin-core/src/options-mapping.ts | 9 +++++---- packages/bundler-plugin-core/src/types.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/bundler-plugin-core/src/options-mapping.ts b/packages/bundler-plugin-core/src/options-mapping.ts index c03ae9e2..8b1976fe 100644 --- a/packages/bundler-plugin-core/src/options-mapping.ts +++ b/packages/bundler-plugin-core/src/options-mapping.ts @@ -1,5 +1,5 @@ import { Logger } from "./sentry/logger"; -import { Options as UserOptions } from "./types"; +import { Options as UserOptions, SetCommitsOptions } from "./types"; import { determineReleaseName } from "./utils"; export type NormalizedOptions = ReturnType; @@ -26,7 +26,10 @@ export function normalizeUserOptions(userOptions: UserOptions) { create: userOptions.release?.create ?? true, finalize: userOptions.release?.finalize ?? true, vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin", - setCommits: userOptions.release?.setCommits, + setCommits: userOptions.release?.setCommits as + | (SetCommitsOptions & { shouldNotThrowOnFailure?: boolean }) + | false + | undefined, }, bundleSizeOptimizations: userOptions.bundleSizeOptimizations, reactComponentAnnotation: userOptions.reactComponentAnnotation, @@ -48,7 +51,6 @@ export function normalizeUserOptions(userOptions: UserOptions) { process.env["VERCEL_GIT_REPO_OWNER"] ) { options.release.setCommits = { - // @ts-expect-error This is fine shouldNotThrowOnFailure: true, commit: process.env["VERCEL_GIT_COMMIT_SHA"], previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"], @@ -59,7 +61,6 @@ export function normalizeUserOptions(userOptions: UserOptions) { } else { options.release.setCommits = { shouldNotThrowOnFailure: true, - // @ts-expect-error This is fine auto: true, ignoreEmpty: true, ignoreMissing: true, diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index bc55427e..9ea12397 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -460,7 +460,7 @@ export interface SentrySDKBuildFlags extends Record __SENTRY_EXCLUDE_REPLAY_WORKER__?: boolean; } -type SetCommitsOptions = (AutoSetCommitsOptions | ManualSetCommitsOptions) & { +export type SetCommitsOptions = (AutoSetCommitsOptions | ManualSetCommitsOptions) & { /** * The commit before the beginning of this release (in other words, * the last commit of the previous release).