-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathgradle.rs
More file actions
152 lines (136 loc) · 5.24 KB
/
gradle.rs
File metadata and controls
152 lines (136 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#![expect(clippy::unwrap_used, reason = "contains legacy code which uses unwrap")]
use std::env;
use std::path::PathBuf;
use std::time::Duration;
use anyhow::Result;
use clap::{Arg, ArgAction, ArgMatches, Command};
use log::{debug, info};
use sourcemap::ram_bundle::RamBundle;
use crate::api::Api;
use crate::config::Config;
use crate::constants::DEFAULT_MAX_WAIT;
use crate::utils::args::{validate_distribution, ArgExt};
use crate::utils::file_search::ReleaseFileSearch;
use crate::utils::file_upload::{SourceFile, UploadContext};
use crate::utils::sourcemaps::SourceMapProcessor;
pub fn make_command(command: Command) -> Command {
command
.about("Upload react-native projects in a gradle build step.")
.org_arg()
.project_arg(false)
.arg(
Arg::new("sourcemap")
.long("sourcemap")
.value_name("PATH")
.required(true)
.help("The path to a sourcemap that should be uploaded."),
)
.arg(
Arg::new("bundle")
.long("bundle")
.value_name("PATH")
.required(true)
.help("The path to a bundle that should be uploaded."),
)
.arg(
Arg::new("release")
.long("release")
.value_name("RELEASE")
.help("The name of the release to publish."),
)
.arg(
Arg::new("dist")
.long("dist")
.value_name("DISTRIBUTION")
.action(ArgAction::Append)
.value_parser(validate_distribution)
.help("The names of the distributions to publish. Can be supplied multiple times."),
)
.arg(
Arg::new("wait")
.long("wait")
.action(ArgAction::SetTrue)
.conflicts_with("wait_for")
.help("Wait for the server to fully process uploaded files."),
)
.arg(
Arg::new("wait_for")
.long("wait-for")
.value_name("SECS")
.value_parser(clap::value_parser!(u64))
.conflicts_with("wait")
.help(
"Wait for the server to fully process uploaded files, \
but at most for the given number of seconds.",
),
)
}
pub fn execute(matches: &ArgMatches) -> Result<()> {
let config = Config::current();
let org = config.get_org(matches)?;
let projects = config.get_projects(matches)?;
let api = Api::current();
let base = env::current_dir()?;
let sourcemap_path = PathBuf::from(matches.get_one::<String>("sourcemap").unwrap());
let bundle_path = PathBuf::from(matches.get_one::<String>("bundle").unwrap());
let sourcemap_url = format!(
"~/{}",
sourcemap_path.file_name().unwrap().to_string_lossy()
);
let bundle_url = format!("~/{}", bundle_path.file_name().unwrap().to_string_lossy());
println!("Processing react-native sourcemaps for Sentry upload.");
info!(" bundle path: {}", bundle_path.display());
info!(" sourcemap path: {}", sourcemap_path.display());
let mut processor = SourceMapProcessor::new();
processor.add(
&bundle_url,
ReleaseFileSearch::collect_file(bundle_path.clone())?,
);
let sourcemap_match = ReleaseFileSearch::collect_file(sourcemap_path.clone())?;
if let Ok(ram_bundle) = RamBundle::parse_unbundle_from_path(&bundle_path) {
debug!("File RAM bundle found, extracting its contents...");
let sourcemap_source = SourceFile::from_release_file_match(&sourcemap_url, sourcemap_match);
processor.unpack_ram_bundle(&ram_bundle, &bundle_url, &sourcemap_source)?;
} else {
debug!("Non-file bundle found");
processor.add(&sourcemap_url, sourcemap_match);
}
processor.rewrite(&[base.to_str().unwrap()])?;
processor.add_sourcemap_references();
processor.add_debug_id_references();
let version = matches.get_one::<String>("release");
let chunk_upload_options = api.authenticated()?.get_chunk_upload_options(&org)?;
let wait_for_secs = matches.get_one::<u64>("wait_for").copied();
let wait = matches.get_flag("wait") || wait_for_secs.is_some();
let max_wait = wait_for_secs.map_or(DEFAULT_MAX_WAIT, Duration::from_secs);
if let Some(version) = version {
for dist in matches.get_many::<String>("dist").unwrap() {
println!("Uploading sourcemaps for release {version} distribution {dist}");
processor.upload(&UploadContext {
org: &org,
projects: &projects,
release: Some(version),
dist: Some(dist),
note: None,
wait,
max_wait,
dedupe: false,
chunk_upload_options: chunk_upload_options.as_ref(),
})?;
}
} else {
// Debug Id Upload
processor.upload(&UploadContext {
org: &org,
projects: &projects,
release: None,
dist: None,
note: None,
wait,
max_wait,
dedupe: false,
chunk_upload_options: chunk_upload_options.as_ref(),
})?;
}
Ok(())
}