Skip to content

Commit d783793

Browse files
feat(build): Add --selective flag to snapshots command (#3268)
Add `--selective` flag to `sentry-cli build snapshots` to indicate the upload contains only a subset of images (e.g. due to sharding or selective test execution). The command validates that every uploaded image is listed in the provided file, failing early if an unknown image is found. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cdcc4a2 commit d783793

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- (snapshots) Add `--selective` flag to `build snapshots` to indicate the upload contains only a subset of images ([#3268](https://github.com/getsentry/sentry-cli/pull/3268))
78
- (bundle-jvm) Allow running directly on a project root (including multi-module repos) by automatically collecting only JVM source files (`.java`, `.kt`, `.scala`, `.groovy`), respecting `.gitignore`, and excluding common build output directories ([#3260](https://github.com/getsentry/sentry-cli/pull/3260))
89
- (bundle-jvm) Add `--exclude` option for custom glob patterns to exclude files/directories from source collection ([#3260](https://github.com/getsentry/sentry-cli/pull/3260))
910

src/api/data_types/snapshots.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub struct SnapshotsManifest<'a> {
2929
/// is greater than this value (e.g. 0.01 = only report changes >= 1%).
3030
#[serde(skip_serializing_if = "Option::is_none")]
3131
pub diff_threshold: Option<f64>,
32+
/// When true, this upload contains only a subset of images.
33+
/// Removals and renames will not be detected on PRs.
34+
#[serde(skip_serializing_if = "std::ops::Not::not")]
35+
pub selective: bool,
3236
#[serde(flatten)]
3337
pub vcs_info: VcsInfo<'a>,
3438
}
@@ -59,6 +63,45 @@ mod tests {
5963

6064
use serde_json::json;
6165

66+
fn empty_vcs_info() -> VcsInfo<'static> {
67+
VcsInfo {
68+
head_sha: None,
69+
base_sha: None,
70+
vcs_provider: "".into(),
71+
head_repo_name: "".into(),
72+
base_repo_name: "".into(),
73+
head_ref: "".into(),
74+
base_ref: "".into(),
75+
pr_number: None,
76+
}
77+
}
78+
79+
#[test]
80+
fn manifest_omits_selective_when_false() {
81+
let manifest = SnapshotsManifest {
82+
app_id: "app".into(),
83+
images: HashMap::new(),
84+
diff_threshold: None,
85+
selective: false,
86+
vcs_info: empty_vcs_info(),
87+
};
88+
let json = serde_json::to_value(&manifest).unwrap();
89+
assert!(!json.as_object().unwrap().contains_key("selective"));
90+
}
91+
92+
#[test]
93+
fn manifest_includes_selective_when_true() {
94+
let manifest = SnapshotsManifest {
95+
app_id: "app".into(),
96+
images: HashMap::new(),
97+
diff_threshold: None,
98+
selective: true,
99+
vcs_info: empty_vcs_info(),
100+
};
101+
let json = serde_json::to_value(&manifest).unwrap();
102+
assert_eq!(json["selective"], json!(true));
103+
}
104+
62105
#[test]
63106
fn cli_managed_fields_override_sidecar_fields() {
64107
let extra = serde_json::from_value(json!({

src/commands/build/snapshots.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ pub fn make_command(command: Command) -> Command {
6868
Example: 0.01 = only report image changes >= 1%.",
6969
),
7070
)
71+
.arg(
72+
Arg::new("selective")
73+
.long("selective")
74+
.action(clap::ArgAction::SetTrue)
75+
.help(
76+
"Indicates this upload contains only a subset of images. \
77+
Removals and renames cannot be detected on PRs.",
78+
),
79+
)
7180
.git_metadata_args()
7281
}
7382

@@ -142,10 +151,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
142151
// Build manifest from discovered images
143152
let diff_threshold = matches.get_one::<f64>("diff_threshold").copied();
144153

154+
let selective = matches.get_flag("selective");
155+
145156
let manifest = SnapshotsManifest {
146157
app_id: app_id.clone(),
147158
images: manifest_entries,
148159
diff_threshold,
160+
selective,
149161
vcs_info,
150162
};
151163

tests/integration/_cases/build/build-snapshots-help.trycmd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@ Options:
3636
--log-level <LOG_LEVEL>
3737
Set the log output verbosity. [possible values: trace, debug, info, warn, error]
3838

39-
--head-sha <head_sha>
40-
The VCS commit sha to use for the upload. If not provided, the current commit sha will be
41-
used.
42-
4339
--quiet
4440
Do not print any output while preserving correct exit code. This flag is currently
4541
implemented only for selected subcommands.
4642

4743
[aliases: --silent]
4844

45+
--selective
46+
Indicates this upload contains only a subset of images. Removals and renames cannot be
47+
detected on PRs.
48+
49+
--head-sha <head_sha>
50+
The VCS commit sha to use for the upload. If not provided, the current commit sha will be
51+
used.
52+
4953
--base-sha <base_sha>
5054
The VCS commit's base sha to use for the upload. If not provided, the merge-base of the
5155
current and remote branch will be used.

0 commit comments

Comments
 (0)