Skip to content

WIP: Upload sourcemaps to multiple projects #2480

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ impl RegionSpecificApi<'_> {
.release()
.map_err(|err| ApiError::with_source(ApiErrorKind::ReleaseNotFound, err))?;

let path = if let Some(project) = context.project {
let path = if let Some(project) = context.projects.get(0) {
format!(
"/projects/{}/{}/releases/{}/files/",
PathArg(context.org),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/debug_files/bundle_jvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {

let context = &UploadContext {
org: &org,
project: project.as_deref(),
projects: project.iter().map(|p| p.as_ref()).collect(),
release: None,
dist: None,
note: None,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/files/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn make_command(command: Command) -> Command {
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
println!("✅ executing ...");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💀

let config = Config::current();
let release = config.get_release_with_legacy_fallback(matches)?;
let org = config.get_org(matches)?;
Expand All @@ -150,7 +151,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {

let context = &UploadContext {
org: &org,
project: project.as_deref(),
projects: project.iter().map(|p| p.as_ref()).collect(),
release: Some(&release),
dist,
note: None,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/react_native/appcenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {

processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: Some(&release),
dist: None,
note: None,
Expand All @@ -214,7 +214,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {

processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: Some(&release),
dist: Some(dist),
note: None,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/react_native/gradle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {

processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: Some(version),
dist: Some(dist),
note: None,
Expand All @@ -142,7 +142,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
// Debug Id Upload
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: None,
dist: None,
note: None,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/react_native/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
if dist_from_env.is_err() && release_from_env.is_err() && matches.get_flag("no_auto_release") {
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: None,
dist: None,
note: None,
Expand Down Expand Up @@ -381,7 +381,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
None => {
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: release_name.as_deref(),
dist: dist.as_deref(),
note: None,
Expand All @@ -395,7 +395,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
for dist in dists {
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: release_name.as_deref(),
dist: Some(dist),
note: None,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let max_wait = wait_for_secs.map_or(DEFAULT_MAX_WAIT, Duration::from_secs);
let upload_context = UploadContext {
org: &org,
project: Some(&project),
projects: vec![&project],
release: version.as_deref(),
dist: matches.get_one::<String>("dist").map(String::as_str),
note: matches.get_one::<String>("note").map(String::as_str),
Expand Down
40 changes: 27 additions & 13 deletions src/utils/file_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn initialize_legacy_release_upload(context: &UploadContext) -> Result<()> {
// need to do anything here. Artifact bundles will also only work
// if a project is provided which is technically unnecessary for the
// legacy upload though it will unlikely to be what users want.
if context.project.is_some()
if !context.projects.is_empty()
&& context.chunk_upload_options.is_some_and(|x| {
x.supports(ChunkUploadCapability::ArtifactBundles)
|| x.supports(ChunkUploadCapability::ArtifactBundlesV2)
Expand All @@ -51,7 +51,7 @@ pub fn initialize_legacy_release_upload(context: &UploadContext) -> Result<()> {
}

// TODO: make this into an error later down the road
if context.project.is_none() {
if context.projects.is_empty() {
eprintln!(
"{}",
style(
Expand All @@ -70,7 +70,11 @@ pub fn initialize_legacy_release_upload(context: &UploadContext) -> Result<()> {
context.org,
&NewRelease {
version: version.to_string(),
projects: context.project.map(|x| x.to_string()).into_iter().collect(),
projects: context
.projects
.iter()
.map(|x| x.to_string())
.collect(),
..Default::default()
},
)?;
Expand All @@ -83,7 +87,8 @@ pub fn initialize_legacy_release_upload(context: &UploadContext) -> Result<()> {
#[derive(Debug, Clone)]
pub struct UploadContext<'a> {
pub org: &'a str,
pub project: Option<&'a str>,
// pub projects: Option<&'a str>,
pub projects: Vec<&'a str>,
pub release: Option<&'a str>,
pub dist: Option<&'a str>,
pub note: Option<&'a str>,
Expand Down Expand Up @@ -235,7 +240,11 @@ fn upload_files_parallel(
// files that already exist.
let release_files: HashMap<_, _> = api
.authenticated()?
.list_release_files(context.org, context.project, release)?
.list_release_files(
context.org,
context.projects.get(0).map(|p| p.to_owned()),
release,
)?
.into_iter()
.map(|artifact| ((artifact.dist, artifact.name), artifact.id))
.collect();
Expand Down Expand Up @@ -281,7 +290,12 @@ fn upload_files_parallel(
release_files.get(&(context.dist.map(|x| x.into()), file.url.clone()))
{
authenticated_api
.delete_release_file(context.org, context.project, release, old_id)
.delete_release_file(
context.org,
context.projects.get(0).map(|p| p.to_owned()),
release,
old_id,
)
.ok();
}

Expand Down Expand Up @@ -337,13 +351,13 @@ fn poll_assemble(
let authenticated_api = api.authenticated()?;
let use_artifact_bundle = (options.supports(ChunkUploadCapability::ArtifactBundles)
|| options.supports(ChunkUploadCapability::ArtifactBundlesV2))
&& context.project.is_some();
&& !context.projects.is_empty();
let response = loop {
// prefer standalone artifact bundle upload over legacy release based upload
let response = if use_artifact_bundle {
authenticated_api.assemble_artifact_bundle(
context.org,
vec![context.project.unwrap().to_string()],
vec![context.projects.get(0).unwrap().to_string()],
checksum,
chunks,
context.release,
Expand Down Expand Up @@ -429,11 +443,11 @@ fn upload_files_chunked(

// Filter out chunks that are already on the server. This only matters if the server supports
// `ArtifactBundlesV2`, otherwise the `missing_chunks` field is meaningless.
if options.supports(ChunkUploadCapability::ArtifactBundlesV2) && context.project.is_some() {
if options.supports(ChunkUploadCapability::ArtifactBundlesV2) && !context.projects.is_empty() {
let api = Api::current();
let response = api.authenticated()?.assemble_artifact_bundle(
context.org,
vec![context.project.unwrap().to_string()],
vec![context.projects.get(0).unwrap().to_string()],
checksum,
&checksums,
context.release,
Expand Down Expand Up @@ -500,7 +514,7 @@ fn build_artifact_bundle(
}

bundle.set_attribute("org".to_owned(), context.org.to_owned());
if let Some(project) = context.project {
if let Some(project) = context.projects.get(0) {
bundle.set_attribute("project".to_owned(), project.to_owned());
}
if let Some(release) = context.release {
Expand Down Expand Up @@ -593,7 +607,7 @@ fn print_upload_context_details(context: &UploadContext) {
println!(
"{} {}",
style("> Project:").dim(),
style(context.project.unwrap_or("None")).yellow()
style(context.projects.get(0).unwrap_or(&"None")).yellow()
);
println!(
"{} {}",
Expand Down Expand Up @@ -657,7 +671,7 @@ mod tests {
fn build_artifact_bundle_deterministic() {
let context = UploadContext {
org: "wat-org",
project: Some("wat-project"),
projects: vec!["wat-project"],
release: None,
dist: None,
note: None,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ impl SourceMapProcessor {
if let Ok(artifacts) = api.authenticated().and_then(|api| {
api.list_release_files_by_checksum(
context.org,
context.project,
context.projects.get(0).map(|p| p.to_owned()),
release,
&sources_checksums,
)
Expand Down
Loading