diff --git a/packages/bundler-plugin-core/src/options-mapping.ts b/packages/bundler-plugin-core/src/options-mapping.ts index fbb65695..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, @@ -41,10 +44,38 @@ 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 = { + 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, + 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 50e0a302..fd00157f 100644 --- a/packages/bundler-plugin-core/src/plugins/release-management.ts +++ b/packages/bundler-plugin-core/src/plugins/release-management.ts @@ -91,14 +91,17 @@ 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)) { - throw e; - } else { + // 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 && + setCommitsOption.shouldNotThrowOnFailure + ) { logger.debug( - "An error occurred setting commits on release (this message can be ignored unless your commits on release are desired):", + "An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):", e ); + } else { + throw e; } } } 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). diff --git a/packages/bundler-plugin-core/test/option-mappings.test.ts b/packages/bundler-plugin-core/test/option-mappings.test.ts index af008ad5..f233e1e7 100644 --- a/packages/bundler-plugin-core/test/option-mappings.test.ts +++ b/packages/bundler-plugin-core/test/option-mappings.test.ts @@ -25,7 +25,9 @@ describe("normalizeUserOptions()", () => { uploadLegacySourcemaps: "./out", setCommits: { auto: true, - isDefault: true, + shouldNotThrowOnFailure: true, + ignoreEmpty: true, + ignoreMissing: true, }, }, silent: false, @@ -80,7 +82,9 @@ describe("normalizeUserOptions()", () => { }, setCommits: { auto: true, - isDefault: true, + shouldNotThrowOnFailure: true, + ignoreEmpty: true, + ignoreMissing: true, }, }, silent: false,