Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sourcemaps): Add no-dedupe flag for skipping deduplication #1334

Merged
merged 1 commit into from
Sep 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/commands/sourcemaps/upload.rs
Expand Up @@ -139,6 +139,11 @@ pub fn make_command(command: Command) -> Command {
.requires_all(&["bundle"])
.help("Path to the bundle sourcemap"),
)
.arg(Arg::new("no_dedupe").long("no-dedupe").help(
"Skip artifacts deduplication prior to uploading. \
This will force all artifacts to be uploaded, \
no matter whether they are already present on the server.",
))
.arg(
Arg::new("extensions")
.long("ext")
Expand Down Expand Up @@ -327,11 +332,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
},
)?;

for artifact in api.list_release_files(&org, Some(&project), &release.version)? {
let checksum = Digest::from_str(&artifact.sha1)
.map_err(|_| format_err!("Invalid artifact checksum"))?;
if !matches.is_present("no_dedupe") {
for artifact in api.list_release_files(&org, Some(&project), &release.version)? {
let checksum = Digest::from_str(&artifact.sha1)
.map_err(|_| format_err!("Invalid artifact checksum"))?;

processor.add_already_uploaded_source(checksum);
processor.add_already_uploaded_source(checksum);
}
}

processor.upload(&UploadContext {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/sourcemaps.rs
Expand Up @@ -548,6 +548,12 @@ impl SourceMapProcessor {
}

fn flag_uploaded_sources(&mut self) {
// There is no point in going through all the sources if nothing was uploaded,
// or we did not collect uploaded files.
if self.already_uploaded_sources.is_empty() {
return;
}

for source in self.sources.values_mut() {
if let Ok(checksum) = &source.checksum() {
if self.already_uploaded_sources.contains(checksum) {
Expand Down
Expand Up @@ -42,6 +42,10 @@ OPTIONS:
--log-level <LOG_LEVEL>
Set the log output verbosity. [possible values: trace, debug, info, warn, error]

--no-dedupe
Skip artifacts deduplication prior to uploading. This will force all artifacts to be
uploaded, no matter whether they are already present on the server.

--no-rewrite
Disables rewriting of matching sourcemaps. By default the tool will rewrite sources, so
that indexed maps are flattened and missing sources are inlined if possible.
Expand Down
@@ -0,0 +1,22 @@
```
$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map tests/integration/_fixtures/vendor.min.js.map --release=wat-release --no-dedupe
? success
> Found 1 release file
> Found 1 release file
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete (processing pending on server)
> Organization: wat-org
> Project: wat-project
> Release: wat-release
> Dist: None

Source Map Upload Report
Source Maps
~/bundle.min.js.map
~/vendor.min.js.map

```
@@ -1,11 +1,12 @@
```
$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map --release=wat-release
$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map tests/integration/_fixtures/vendor.min.js.map --release=wat-release
? success
> Found 1 release file
> Analyzing 1 sources
> Found 1 release file
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
> Bundled 1 file for upload
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete (processing pending on server)
> Organization: wat-org
Expand All @@ -15,6 +16,7 @@ $ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map --r

Source Map Upload Report
Source Maps
~/bundle.min.js.map (skipped; already uploaded)
~/bundle.min.js.map
~/vendor.min.js.map (skipped; already uploaded)

```
1 change: 1 addition & 0 deletions tests/integration/_fixtures/vendor.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions tests/integration/sourcemaps/upload.rs
Expand Up @@ -38,10 +38,10 @@ fn command_sourcemaps_upload_skip_already_uploaded() {
.with_response_body(
r#"[{
"id": "1337",
"name": "~/bundle.min.js.map",
"name": "~/vendor.min.js.map",
"headers": {},
"size": 1522,
"sha1": "38ed853073df85147960ea3a5bced6170ec389b0",
"sha1": "f3673e2cea68bcb86bb74254a9efaa381d74929f",
"dateCreated": "2022-05-12T11:08:01.496220Z"
}]"#,
),
Expand All @@ -50,6 +50,30 @@ fn command_sourcemaps_upload_skip_already_uploaded() {
register_test("sourcemaps/sourcemaps-upload-skip-already-uploaded.trycmd");
}

#[test]
fn command_sourcemaps_upload_no_dedupe() {
let _upload_endpoints = mock_common_upload_endpoints();
let _files = mock_endpoint(
EndpointOptions::new(
"GET",
"/api/0/projects/wat-org/wat-project/releases/wat-release/files/?cursor=",
200,
)
.with_response_body(
r#"[{
"id": "1337",
"name": "~/vendor.min.js.map",
"headers": {},
"size": 1522,
"sha1": "f3673e2cea68bcb86bb74254a9efaa381d74929f",
"dateCreated": "2022-05-12T11:08:01.496220Z"
}]"#,
),
);

register_test("sourcemaps/sourcemaps-upload-no-dedupe.trycmd");
}

// Endpoints need to be bound, as they need to live long enough for test to finish
fn mock_common_upload_endpoints() -> Vec<Mock> {
let chunk_upload_response = format!(
Expand Down