diff --git a/CHANGELOG.md b/CHANGELOG.md index cdae4a1607..d767c61a44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Added `sentry-cli proguard uuid ` to compute and print the UUID for a ProGuard mapping file ([#3176](https://github.com/getsentry/sentry-cli/pull/3176)). + ### Improvements - Moved `sentry-cli upload-proguard` to `sentry-cli proguard upload`, aligning the API with similar upload commands like `debug-files upload` and `sourcemaps upload` ([#3174](https://github.com/getsentry/sentry-cli/pull/3174)). `sentry-cli upload-proguard` remains supported as an alias, so no migration is required. diff --git a/src/commands/proguard/mod.rs b/src/commands/proguard/mod.rs index d7f3bad30a..d7e12f9199 100644 --- a/src/commands/proguard/mod.rs +++ b/src/commands/proguard/mod.rs @@ -2,10 +2,12 @@ use anyhow::Result; use clap::{ArgMatches, Command}; pub mod upload; +pub mod uuid; macro_rules! each_subcommand { ($mac:ident) => { $mac!(upload); + $mac!(uuid); }; } diff --git a/src/commands/proguard/uuid.rs b/src/commands/proguard/uuid.rs new file mode 100644 index 0000000000..188825afee --- /dev/null +++ b/src/commands/proguard/uuid.rs @@ -0,0 +1,37 @@ +use anyhow::{Context as _, Result}; +use clap::{Arg, ArgMatches, Command}; +use symbolic::common::ByteView; + +use crate::utils::proguard::ProguardMapping; + +pub fn make_command(command: Command) -> Command { + command + .about("Compute the UUID for a ProGuard mapping file.") + .long_about( + "Compute the UUID for a ProGuard mapping file.\n\n\ + This command computes and prints to stdout the UUID of the ProGuard \ + mapping at the specified path. This is the UUID that will be set by \ + the `proguard upload` command. The UUID is deterministicly computed \ + based on the file contents.", + ) + .arg( + Arg::new("path") + .value_name("PATH") + .help("The path to the mapping file.") + .required(true), + ) +} + +pub fn execute(matches: &ArgMatches) -> Result<()> { + let path = matches + .get_one::("path") + .expect("required argument"); + + let byteview = ByteView::open(path) + .with_context(|| format!("failed to open proguard mapping '{path}'"))?; + let mapping = ProguardMapping::try_from(byteview) + .with_context(|| format!("failed to parse proguard mapping '{path}'"))?; + + println!("{}", mapping.uuid()); + Ok(()) +} diff --git a/tests/integration/_cases/proguard/proguard-help.trycmd b/tests/integration/_cases/proguard/proguard-help.trycmd index ffb4317cdc..66700a5671 100644 --- a/tests/integration/_cases/proguard/proguard-help.trycmd +++ b/tests/integration/_cases/proguard/proguard-help.trycmd @@ -7,6 +7,7 @@ Usage: sentry-cli[EXE] proguard [OPTIONS] Commands: upload Upload ProGuard mapping files to a project. + uuid Compute the UUID for a ProGuard mapping file. help Print this message or the help of the given subcommand(s) Options: diff --git a/tests/integration/_cases/proguard/proguard-uuid-help.trycmd b/tests/integration/_cases/proguard/proguard-uuid-help.trycmd new file mode 100644 index 0000000000..7815d142ea --- /dev/null +++ b/tests/integration/_cases/proguard/proguard-uuid-help.trycmd @@ -0,0 +1,36 @@ +``` +$ sentry-cli proguard uuid --help +? success +Compute the UUID for a ProGuard mapping file. + +This command computes and prints to stdout the UUID of the ProGuard mapping at the specified path. +This is the UUID that will be set by the `proguard upload` command. The UUID is deterministicly +computed based on the file contents. + +Usage: sentry-cli[EXE] proguard uuid [OPTIONS] + +Arguments: + + The path to the mapping file. + +Options: + --header + Custom headers that should be attached to all requests + in key:value format. + + --auth-token + Use the given Sentry auth token. + + --log-level + Set the log output verbosity. [possible values: trace, debug, info, warn, error] + + --quiet + Do not print any output while preserving correct exit code. This flag is currently + implemented only for selected subcommands. + + [aliases: --silent] + + -h, --help + Print help (see a summary with '-h') + +``` diff --git a/tests/integration/_cases/proguard/proguard-uuid-invalid-mapping.trycmd b/tests/integration/_cases/proguard/proguard-uuid-invalid-mapping.trycmd new file mode 100644 index 0000000000..18cb2afed4 --- /dev/null +++ b/tests/integration/_cases/proguard/proguard-uuid-invalid-mapping.trycmd @@ -0,0 +1,12 @@ +``` +$ sentry-cli proguard uuid tests/integration/_fixtures/proguard.txt +? failed +error: failed to parse proguard mapping 'tests/integration/_fixtures/proguard.txt' + +Caused by: + Proguard mapping does not contain line information + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/proguard/proguard-uuid-missing-file.trycmd b/tests/integration/_cases/proguard/proguard-uuid-missing-file.trycmd new file mode 100644 index 0000000000..64208d6c2a --- /dev/null +++ b/tests/integration/_cases/proguard/proguard-uuid-missing-file.trycmd @@ -0,0 +1,12 @@ +``` +$ sentry-cli proguard uuid tests/integration/_fixtures/proguard/upload/does-not-exist.txt +? failed +error: failed to open proguard mapping 'tests/integration/_fixtures/proguard/upload/does-not-exist.txt' + +Caused by: + [..] + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/proguard/proguard-uuid-success.trycmd b/tests/integration/_cases/proguard/proguard-uuid-success.trycmd new file mode 100644 index 0000000000..10f2cabbdc --- /dev/null +++ b/tests/integration/_cases/proguard/proguard-uuid-success.trycmd @@ -0,0 +1,6 @@ +``` +$ sentry-cli proguard uuid tests/integration/_fixtures/proguard/upload/mapping.txt +? success +c038584d-c366-570c-ad1e-034fa0d194d7 + +``` diff --git a/tests/integration/proguard/mod.rs b/tests/integration/proguard/mod.rs index f8802ec1d8..b5bbd3e11a 100644 --- a/tests/integration/proguard/mod.rs +++ b/tests/integration/proguard/mod.rs @@ -1 +1,2 @@ mod upload; +mod uuid; diff --git a/tests/integration/proguard/uuid.rs b/tests/integration/proguard/uuid.rs new file mode 100644 index 0000000000..01d29b0495 --- /dev/null +++ b/tests/integration/proguard/uuid.rs @@ -0,0 +1,6 @@ +use crate::integration::TestManager; + +#[test] +fn command_proguard_uuid() { + TestManager::new().register_trycmd_test("proguard/proguard-uuid*.trycmd"); +}