Skip to content

Commit cb3cb61

Browse files
committed
ref(core): Use Sentry CLI for artifact deletion
1 parent dd8f9f2 commit cb3cb61

File tree

3 files changed

+12
-48
lines changed

3 files changed

+12
-48
lines changed

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,3 @@ export async function createRelease({
4949
throw e;
5050
}
5151
}
52-
53-
export async function deleteAllReleaseArtifacts({
54-
org,
55-
project,
56-
release,
57-
authToken,
58-
sentryUrl,
59-
sentryHub,
60-
customHeader,
61-
}: {
62-
org: string;
63-
release: string;
64-
sentryUrl: string;
65-
authToken: string;
66-
project: string;
67-
sentryHub: Hub;
68-
customHeader: Record<string, string>;
69-
}): Promise<void> {
70-
const requestUrl = `${sentryUrl}${API_PATH}/projects/${org}/${project}/files/source-maps/?name=${release}`;
71-
72-
try {
73-
await sentryApiAxiosInstance({ authToken, customHeader }).delete(requestUrl, {
74-
headers: {
75-
Authorization: `Bearer ${authToken}`,
76-
},
77-
});
78-
} catch (e) {
79-
captureMinimalError(e, sentryHub);
80-
throw e;
81-
}
82-
}

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

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

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

88
/**
@@ -57,6 +57,10 @@ function getDryRunCLI(cli: SentryCli, logger: Logger): SentryDryRunCLI {
5757
logger.info("Calling deploy with:\n", config);
5858
return Promise.resolve(release);
5959
},
60+
execute: (args: string[], live: boolean) => {
61+
logger.info("Executing", args, "live:", live);
62+
return Promise.resolve("");
63+
},
6064
},
6165
};
6266
}

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { InternalOptions } from "../options-mapping";
1010
import { BuildContext } from "../types";
11-
import { createRelease, deleteAllReleaseArtifacts } from "./api";
11+
import { createRelease } from "./api";
1212
import { addSpanToTransaction } from "./telemetry";
1313

1414
export async function createNewRelease(
@@ -86,40 +86,31 @@ export async function finalizeRelease(options: InternalOptions, ctx: BuildContex
8686
span?.finish();
8787
}
8888

89-
export async function cleanArtifacts(options: InternalOptions, ctx: BuildContext): Promise<string> {
89+
export async function cleanArtifacts(options: InternalOptions, ctx: BuildContext): Promise<void> {
9090
const span = addSpanToTransaction(ctx, "function.plugin.clean_artifacts");
9191

9292
if (options.cleanArtifacts) {
9393
// TODO: pull these checks out of here and simplify them
9494
if (options.authToken === undefined) {
9595
ctx.logger.warn('Missing "authToken" option. Will not clean existing artifacts.');
96-
return Promise.resolve("nothing to do here");
96+
return;
9797
} else if (options.org === undefined) {
9898
ctx.logger.warn('Missing "org" option. Will not clean existing artifacts.');
99-
return Promise.resolve("nothing to do here");
99+
return;
100100
} else if (options.url === undefined) {
101101
ctx.logger.warn('Missing "url" option. Will not clean existing artifacts.');
102-
return Promise.resolve("nothing to do here");
102+
return;
103103
} else if (options.project === undefined) {
104104
ctx.logger.warn('Missing "project" option. Will not clean existing artifacts.');
105-
return Promise.resolve("nothing to do here");
105+
return;
106106
}
107107

108-
await deleteAllReleaseArtifacts({
109-
authToken: options.authToken,
110-
org: options.org,
111-
release: options.release,
112-
sentryUrl: options.url,
113-
project: options.project,
114-
sentryHub: ctx.hub,
115-
customHeader: options.customHeader,
116-
});
108+
await ctx.cli.releases.execute(["releases", "files", options.release, "delete", "--all"], true);
117109

118110
ctx.logger.info("Successfully cleaned previous artifacts.");
119111
}
120112

121113
span?.finish();
122-
return Promise.resolve("nothing to do here");
123114
}
124115

125116
// TODO: Stuff we worry about later:

0 commit comments

Comments
 (0)