-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
gradle.rs
126 lines (112 loc) · 3.91 KB
/
gradle.rs
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
use std::env;
use std::path::PathBuf;
use anyhow::Result;
use clap::{Arg, ArgMatches, Command};
use log::{debug, info};
use sourcemap::ram_bundle::RamBundle;
use crate::api::{Api, NewRelease};
use crate::config::Config;
use crate::utils::args::{validate_distribution, ArgExt};
use crate::utils::file_search::ReleaseFileSearch;
use crate::utils::file_upload::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")
.required(true)
.help("The name of the release to publish."),
)
.arg(
Arg::new("dist")
.long("dist")
.value_name("DISTRIBUTION")
.required(true)
.multiple_occurrences(true)
.validator(validate_distribution)
.help("The names of the distributions to publish. Can be supplied multiple times."),
)
.arg(
Arg::new("wait")
.long("wait")
.help("Wait for the server to fully process uploaded files."),
)
}
pub fn execute(matches: &ArgMatches) -> Result<()> {
let config = Config::current();
let (org, project) = config.get_org_and_project(matches)?;
let api = Api::current();
let base = env::current_dir()?;
let sourcemap_path = PathBuf::from(matches.value_of("sourcemap").unwrap());
let bundle_path = PathBuf::from(matches.value_of("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());
info!(
"Issuing a command for Organization: {} Project: {}",
org, project
);
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())?,
)?;
processor.add(
&sourcemap_url,
ReleaseFileSearch::collect_file(sourcemap_path)?,
)?;
if let Ok(ram_bundle) = RamBundle::parse_unbundle_from_path(&bundle_path) {
debug!("File RAM bundle found, extracting its contents...");
processor.unpack_ram_bundle(&ram_bundle, &bundle_url)?;
} else {
debug!("Non-file bundle found");
}
processor.rewrite(&[base.to_str().unwrap()])?;
processor.add_sourcemap_references()?;
let release = api.new_release(
&org,
&NewRelease {
version: matches.value_of("release").unwrap().to_string(),
projects: vec![project.to_string()],
..Default::default()
},
)?;
for dist in matches.values_of("dist").unwrap() {
println!(
"Uploading sourcemaps for release {} distribution {}",
&release.version, dist
);
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
release: &release.version,
dist: Some(dist),
wait: matches.is_present("wait"),
})?;
}
Ok(())
}