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

ref(sourcemaps): Skip empty SourceMap uploads #1552

Merged
merged 2 commits into from
Mar 30, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/utils/file_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn upload_files_chunked(
));

upload_chunks(&chunks, options, progress_style)?;
println!("{} Uploaded release files to Sentry", style(">").dim(),);
println!("{} Uploaded release files to Sentry", style(">").dim());

let progress_style = ProgressStyle::default_spinner().template("{spinner} Processing files...");

Expand Down Expand Up @@ -443,6 +443,8 @@ fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result

bundle.finish()?;

pb.finish_with_duration("Bundling");

println!(
"{} Bundled {} {} for upload",
style(">").dim(),
Expand All @@ -453,8 +455,6 @@ fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result
}
);

pb.finish_with_duration("Bundling");

Ok(archive)
}

Expand Down
30 changes: 20 additions & 10 deletions src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,18 @@ impl SourceMapProcessor {
Ok(())
}

fn flag_uploaded_sources(&mut self, context: &UploadContext<'_>) {
/// Flags the collected sources whether they have already been uploaded before
/// (based on their checksum), and returns the number of files that *do* need an upload.
fn flag_uploaded_sources(&mut self, context: &UploadContext<'_>) -> usize {
let mut files_needing_upload = self.sources.len();

// TODO: this endpoint does not exist for non release based uploads
if !context.dedupe {
return;
return files_needing_upload;
}
let release = match context.release {
Some(release) => release,
None => return,
None => return files_needing_upload,
};

let mut sources_checksums: Vec<_> = self
Expand All @@ -618,30 +622,36 @@ impl SourceMapProcessor {
release,
&sources_checksums,
) {
let already_uploaded_checksums: Vec<_> = artifacts
.iter()
let already_uploaded_checksums: HashSet<_> = artifacts
.into_iter()
.filter_map(|artifact| Digest::from_str(&artifact.sha1).ok())
.collect();

for mut source in self.sources.values_mut() {
if let Ok(checksum) = source.checksum() {
if already_uploaded_checksums.contains(&checksum) {
source.already_uploaded = true;
files_needing_upload -= 1;
}
}
}
}
files_needing_upload
}

/// Uploads all files
pub fn upload(&mut self, context: &UploadContext<'_>) -> Result<()> {
initialize_legacy_release_upload(context)?;
self.flush_pending_sources();
self.flag_uploaded_sources(context);
let mut uploader = FileUpload::new(context);
uploader.files(&self.sources);
uploader.upload()?;
self.dump_log("Source Map Upload Report");
let files_needing_upload = self.flag_uploaded_sources(context);
if files_needing_upload > 0 {
let mut uploader = FileUpload::new(context);
uploader.files(&self.sources);
uploader.upload()?;
self.dump_log("Source Map Upload Report");
} else {
println!("{} Nothing to upload", style(">").dim());
}
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ $ sentry-cli releases files wat-release upload-sourcemaps --url-prefix '~/assets
? success
> Rewriting sources
> Adding source map references
> Bundled 0 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
> Upload type: release bundle

Source Map Upload Report
> Nothing to upload

```
5 changes: 2 additions & 3 deletions tests/integration/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ fn command_sourcemaps_upload_modern() {
}

#[test]
fn command_releases_files_upload_sourcemap() {
let upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy);
fn command_sourcemaps_upload_empty() {
let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy);
let _files = mock_endpoint(
EndpointOptions::new(
"GET",
Expand All @@ -157,5 +157,4 @@ fn command_releases_files_upload_sourcemap() {
.with_response_body("[]"),
);
register_test("releases/releases-files-upload-sourcemaps.trycmd");
assert_endpoints(&upload_endpoints);
}