@smbcloud / smbcloud-ascapi Mirror · read-only / commits / 2aa5b57
Fork 0

Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.

Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git

Synced Nov 25, 09:15 UTC

Add asc play bundles upload

Upload an .aab into an edit and put it on a track as a new release, so a release no longer starts with a manual Console upload. The file is checked locally first (a zip with base/manifest/AndroidManifest.xml). After the upload, Play's SHA-256 must match the local one, an optional mapping.txt is attached, and a draft or inProgress release on the track is replaced while completed ones stay. The track is read back after the commit. The output carries the versionCode for chaining into tracks set-notes or promote. --dry-run runs only the local checks and needs no credentials. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Seto Elkahfi committed Nov 8, 2026 at 14:17 UTC 2aa5b57cf2fcbb4c41c1251d7043163a11e582f2
8 files changed +574 -4
.agents/AGENTS.md
+11 -1
@@ -314,6 +314,8 @@ asc play images list <PACKAGE> --locale en-US --type phone-screenshots
314 asc play images replace <PACKAGE> --locale en-US --type phone-screenshots --file a.png --file b.png
315 asc play tracks get <PACKAGE> --track internal
316 asc play tracks set-notes <PACKAGE> --track internal --version-code 120 --locale en-US --notes-file n.txt
317 +asc play bundles upload <PACKAGE> --file app.aab --track internal \
318 + [--status draft|completed] [--mapping-file mapping.txt] [--ack-install-warning]
319 asc play products list <PACKAGE>
320 asc play products create <PACKAGE> --id app.unlock --title "Unlock" --description "..." \
321 --price 4.99 --language en-GB # --dry-run prints the body and sends nothing
@@ -325,7 +327,15 @@ Limits linted before sending: title 30, short description 80, full description
327 `images replace` deletes the bucket and uploads the files in one edit, so a
328 failed upload keeps the old set. MCP exposes only the reads
329 (`play_listing_list`, `play_images_list`, `play_track_get`); every write stays
328 -CLI-only, like review submission. One-time products are not inside an edit:
330 +CLI-only, like review submission. `bundles upload` puts an `.aab` on a track in
331 +one edit: it uploads, compares Play's SHA-256 with the local file's, optionally
332 +attaches a ProGuard `mapping.txt`, replaces a `draft` or `inProgress` release on
333 +the track (`completed` ones stay), commits and reads the track back. It prints
334 +the `versionCode` Play assigned, for `tracks set-notes` or `tracks promote`. The
335 +default status is `draft`. `--dry-run` is local only (the file is a zip with
336 +`base/manifest/AndroidManifest.xml`, the mapping file exists) and needs no
337 +credentials; it cannot report the version code. A real upload uses up its
338 +version code permanently, even if the edit fails afterwards. One-time products are not inside an edit:
339 `products create` converts one price to every region
340 (`pricing:convertRegionPrices`), creates the product with `onetimeproducts.patch`
341 (`allowMissing`), activates its purchase option and reads it back; it refuses an
Cargo.lock
+78 -2
@@ -73,6 +73,15 @@ version = "1.0.104"
73 source = "registry+https://github.com/rust-lang/crates.io-index"
74 checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
75
76 +[[package]]
77 +name = "arbitrary"
78 +version = "1.5.0"
79 +source = "registry+https://github.com/rust-lang/crates.io-index"
80 +checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
81 +dependencies = [
82 + "derive_arbitrary",
83 +]
84 +
85 [[package]]
86 name = "asn1-rs"
87 version = "0.7.2"
@@ -357,13 +366,19 @@ dependencies = [
366
367 [[package]]
368 name = "crc32fast"
360 -version = "1.5.1"
369 +version = "1.5.4"
370 source = "registry+https://github.com/rust-lang/crates.io-index"
362 -checksum = "8498c871161e1742aaa9d52551b2d6ebdd4c3d45a3be423e3728f33b955be550"
371 +checksum = "5f97d3416d5337d15c4b0d78c8c91df922ca143f57ec20e2d1c188333047ef04"
372 dependencies = [
373 "cfg-if",
374 ]
375
376 +[[package]]
377 +name = "crossbeam-utils"
378 +version = "0.8.23"
379 +source = "registry+https://github.com/rust-lang/crates.io-index"
380 +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
381 +
382 [[package]]
383 name = "crypto-common"
384 version = "0.1.7"
@@ -466,6 +481,17 @@ version = "0.5.8"
481 source = "registry+https://github.com/rust-lang/crates.io-index"
482 checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
483
484 +[[package]]
485 +name = "derive_arbitrary"
486 +version = "1.5.0"
487 +source = "registry+https://github.com/rust-lang/crates.io-index"
488 +checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac"
489 +dependencies = [
490 + "proc-macro2",
491 + "quote",
492 + "syn 3.0.5",
493 +]
494 +
495 [[package]]
496 name = "digest"
497 version = "0.10.7"
@@ -500,6 +526,12 @@ version = "1.0.20"
526 source = "registry+https://github.com/rust-lang/crates.io-index"
527 checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
528
529 +[[package]]
530 +name = "equivalent"
531 +version = "1.0.3"
532 +source = "registry+https://github.com/rust-lang/crates.io-index"
533 +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
534 +
535 [[package]]
536 name = "find-msvc-tools"
537 version = "0.1.12"
@@ -657,6 +689,12 @@ dependencies = [
689 "wasm-bindgen",
690 ]
691
692 +[[package]]
693 +name = "hashbrown"
694 +version = "0.17.1"
695 +source = "registry+https://github.com/rust-lang/crates.io-index"
696 +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
697 +
698 [[package]]
699 name = "heck"
700 version = "0.5.0"
@@ -895,6 +933,16 @@ dependencies = [
933 "icu_properties",
934 ]
935
936 +[[package]]
937 +name = "indexmap"
938 +version = "2.14.2"
939 +source = "registry+https://github.com/rust-lang/crates.io-index"
940 +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
941 +dependencies = [
942 + "equivalent",
943 + "hashbrown",
944 +]
945 +
946 [[package]]
947 name = "ipnet"
948 version = "2.12.2"
@@ -1833,6 +1881,7 @@ dependencies = [
1881 "smbcloud-ascapi-play",
1882 "smbcloud-ascapi-signing",
1883 "tokio",
1884 + "zip",
1885 ]
1886
1887 [[package]]
@@ -2636,6 +2685,21 @@ dependencies = [
2685 "syn 3.0.5",
2686 ]
2687
2688 +[[package]]
2689 +name = "zip"
2690 +version = "2.6.1"
2691 +source = "registry+https://github.com/rust-lang/crates.io-index"
2692 +checksum = "1dcb24d0152526ae49b9b96c1dcf71850ca1e0b882e4e28ed898a93c41334744"
2693 +dependencies = [
2694 + "arbitrary",
2695 + "crc32fast",
2696 + "crossbeam-utils",
2697 + "flate2",
2698 + "indexmap",
2699 + "memchr",
2700 + "zopfli",
2701 +]
2702 +
2703 [[package]]
2704 name = "zlib-rs"
2705 version = "0.6.7"
@@ -2647,3 +2711,15 @@ name = "zmij"
2711 version = "1.0.23"
2712 source = "registry+https://github.com/rust-lang/crates.io-index"
2713 checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
2714 +
2715 +[[package]]
2716 +name = "zopfli"
2717 +version = "0.8.4"
2718 +source = "registry+https://github.com/rust-lang/crates.io-index"
2719 +checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11"
2720 +dependencies = [
2721 + "bumpalo",
2722 + "crc32fast",
2723 + "log",
2724 + "simd-adler32",
2725 +]
crates/cli/src/main.rs
+87
@@ -113,6 +113,11 @@ enum PlayCommand {
113 #[command(subcommand)]
114 command: PlayTracksCommand,
115 },
116 + /// Upload an app bundle (.aab) to a track.
117 + Bundles {
118 + #[command(subcommand)]
119 + command: PlayBundlesCommand,
120 + },
121 /// One-time products (in-app products): list, read, create.
122 Products {
123 #[command(subcommand)]
@@ -632,6 +637,36 @@ enum PlayTracksCommand {
637 MaxVersionCode { package: String },
638 }
639
640 +#[derive(Subcommand)]
641 +enum PlayBundlesCommand {
642 + /// Upload an .aab and put it on a track as a new release, in one edit.
643 + /// Play's SHA-256 is compared with the local file's and the track is read
644 + /// back after the commit. A draft or inProgress release on the track is
645 + /// replaced; completed ones stay. The version code is printed so a script
646 + /// can chain `tracks set-notes` or `tracks promote`. A real upload uses up
647 + /// its version code for good. With `--dry-run` only local checks run and
648 + /// nothing is sent: the file is a zip with a base manifest, and the
649 + /// mapping file exists.
650 + Upload {
651 + package: String,
652 + /// The .aab to upload.
653 + #[arg(long)]
654 + file: PathBuf,
655 + #[arg(long)]
656 + track: String,
657 + /// Release status on the track: draft (the default) or completed.
658 + #[arg(long, default_value = "draft")]
659 + status: String,
660 + /// ProGuard/R8 mapping.txt for the uploaded version code.
661 + #[arg(long)]
662 + mapping_file: Option<PathBuf>,
663 + /// Accept an install-time warning Play would otherwise refuse the
664 + /// bundle for.
665 + #[arg(long)]
666 + ack_install_warning: bool,
667 + },
668 +}
669 +
670 #[derive(Subcommand)]
671 enum PlayProductsCommand {
672 /// Every one-time product of the app.
@@ -1259,6 +1294,35 @@ async fn run_play(
1294 dry_run: bool,
1295 ) -> Result<()> {
1296 use smbcloud_ascapi_frontend::play;
1297 + // A bundle dry run is local: no credentials needed, nothing sent.
1298 + if let PlayCommand::Bundles {
1299 + command:
1300 + PlayBundlesCommand::Upload {
1301 + package,
1302 + file,
1303 + track,
1304 + status,
1305 + mapping_file,
1306 + ack_install_warning,
1307 + },
1308 + } = &command
1309 + {
1310 + if dry_run {
1311 + let plan = play::plan_bundle_upload(
1312 + package,
1313 + track,
1314 + file,
1315 + status,
1316 + mapping_file.as_deref(),
1317 + *ack_install_warning,
1318 + )
1319 + .map_err(|e| anyhow::anyhow!(e))?;
1320 + println!(
1321 + "# dry run: nothing was sent; the version code is assigned by Play on upload:"
1322 + );
1323 + return print_json(&plan);
1324 + }
1325 + }
1326 let client = play::play_client(service_account).map_err(|e| anyhow::anyhow!(e))?;
1327 let fail = |e: String| anyhow::anyhow!(e);
1328 match command {
@@ -1426,6 +1490,29 @@ async fn run_play(
1490 Ok(())
1491 }
1492 },
1493 + PlayCommand::Bundles { command } => match command {
1494 + PlayBundlesCommand::Upload {
1495 + package,
1496 + file,
1497 + track,
1498 + status,
1499 + mapping_file,
1500 + ack_install_warning,
1501 + } => {
1502 + let result = play::upload_bundle(
1503 + &client,
1504 + &package,
1505 + &track,
1506 + &file,
1507 + &status,
1508 + mapping_file.as_deref(),
1509 + ack_install_warning,
1510 + )
1511 + .await
1512 + .map_err(fail)?;
1513 + print_json(&result)
1514 + }
1515 + },
1516 PlayCommand::Products { command } => match command {
1517 PlayProductsCommand::List { package } => {
1518 print_json(&play::read_products(&client, &package).await.map_err(fail)?)
crates/frontend/Cargo.toml
+1
@@ -24,3 +24,4 @@ smbcloud-ascapi-core = { workspace = true }
24 smbcloud-ascapi-play = { workspace = true }
25 smbcloud-ascapi-signing = { workspace = true }
26 tokio = { workspace = true, features = ["time"] }
27 +zip = { version = "2", default-features = false, features = ["deflate"] }
crates/frontend/src/play.rs
+227
@@ -375,6 +375,174 @@ pub async fn set_track_notes(
375 Ok(NotesSet { dry_run, track })
376 }
377
378 +/// The manifest every Android App Bundle carries.
379 +const BUNDLE_MANIFEST: &str = "base/manifest/AndroidManifest.xml";
380 +
381 +/// A bundle checked on disk, ready to upload.
382 +#[derive(Debug, Serialize)]
383 +#[serde(rename_all = "camelCase")]
384 +pub struct BundleFile {
385 + pub path: PathBuf,
386 + pub bytes: u64,
387 + /// Lowercase hex SHA-256 of the file, to compare with Play's.
388 + pub sha256: String,
389 +}
390 +
391 +/// Check a file is an `.aab` (a zip with `base/manifest/AndroidManifest.xml`)
392 +/// and hash it. Nothing is sent.
393 +pub fn load_bundle(path: &Path) -> Result<(BundleFile, Vec<u8>), String> {
394 + let bytes = std::fs::read(path).map_err(|e| format!("cannot read {}: {e}", path.display()))?;
395 + let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes.as_slice()))
396 + .map_err(|_| format!("{} is not a zip archive, so not an .aab", path.display()))?;
397 + if archive.by_name(BUNDLE_MANIFEST).is_err() {
398 + return Err(format!(
399 + "{} has no {BUNDLE_MANIFEST}; it is a zip but not an Android App Bundle",
400 + path.display()
401 + ));
402 + }
403 + let file = BundleFile {
404 + path: path.to_path_buf(),
405 + bytes: bytes.len() as u64,
406 + sha256: hex(&Sha256::digest(&bytes)),
407 + };
408 + Ok((file, bytes))
409 +}
410 +
411 +fn check_upload_status(status: &str) -> Result<(), String> {
412 + match status {
413 + "draft" | "completed" => Ok(()),
414 + other => Err(format!(
415 + "status {other:?} is not supported for an upload; use draft or completed"
416 + )),
417 + }
418 +}
419 +
420 +/// What `bundles upload --dry-run` reports. A dry run cannot know the version
421 +/// code: Play assigns it on upload.
422 +#[derive(Debug, Serialize)]
423 +#[serde(rename_all = "camelCase")]
424 +pub struct BundlePlan {
425 + pub dry_run: bool,
426 + pub package: String,
427 + pub track: String,
428 + pub status: String,
429 + pub bundle: BundleFile,
430 + pub mapping_file: Option<PathBuf>,
431 + pub ack_install_warning: bool,
432 +}
433 +
434 +/// The local half of `bundles upload`: everything that can be checked without
435 +/// sending anything.
436 +pub fn plan_bundle_upload(
437 + package: &str,
438 + track: &str,
439 + file: &Path,
440 + status: &str,
441 + mapping_file: Option<&Path>,
442 + ack_install_warning: bool,
443 +) -> Result<BundlePlan, String> {
444 + check_upload_status(status)?;
445 + let (bundle, _) = load_bundle(file)?;
446 + if let Some(mapping) = mapping_file {
447 + if !mapping.is_file() {
448 + return Err(format!("mapping file {} does not exist", mapping.display()));
449 + }
450 + }
451 + Ok(BundlePlan {
452 + dry_run: true,
453 + package: package.to_string(),
454 + track: track.to_string(),
455 + status: status.to_string(),
456 + bundle,
457 + mapping_file: mapping_file.map(Path::to_path_buf),
458 + ack_install_warning,
459 + })
460 +}
461 +
462 +#[derive(Debug, Serialize)]
463 +#[serde(rename_all = "camelCase")]
464 +pub struct BundleUploaded {
465 + /// Assigned by Play; use it with `tracks set-notes` or `tracks promote`.
466 + pub version_code: u64,
467 + pub sha256: String,
468 + pub status: String,
469 + pub mapping_uploaded: bool,
470 + /// The track as read back after the commit.
471 + pub track: Track,
472 +}
473 +
474 +/// Whether the read-back track shows `code` on a release at `status`.
475 +fn bundle_landed(track: &Track, code: &str, status: &str) -> bool {
476 + track
477 + .releases
478 + .iter()
479 + .any(|r| r.version_codes.iter().any(|c| c == code) && r.status.as_deref() == Some(status))
480 +}
481 +
482 +/// Upload an `.aab`, optionally its mapping file, and put it on `track_name`
483 +/// as a new release, in one edit. Play's SHA-256 must match the local one, and
484 +/// the track is read back after the commit. The version code is consumed on
485 +/// upload, so a failure after that point still uses one up.
486 +pub async fn upload_bundle(
487 + client: &PlayClient,
488 + package: &str,
489 + track_name: &str,
490 + file: &Path,
491 + status: &str,
492 + mapping_file: Option<&Path>,
493 + ack_install_warning: bool,
494 +) -> Result<BundleUploaded, String> {
495 + check_upload_status(status)?;
496 + let (bundle, bytes) = load_bundle(file)?;
497 + let mapping = match mapping_file {
498 + Some(p) => Some(std::fs::read(p).map_err(|e| format!("cannot read {}: {e}", p.display()))?),
499 + None => None,
500 + };
501 + let mapping_uploaded = mapping.is_some();
502 + let local_sha = bundle.sha256;
503 + let expected = local_sha.as_str();
504 + let version_code = in_edit!(client, package, true, |c, id| {
505 + Box::pin(async move {
506 + let uploaded = c
507 + .upload_bundle(package, id, bytes, ack_install_warning)
508 + .await
509 + .map_err(err)?;
510 + if !uploaded.sha256.eq_ignore_ascii_case(expected) {
511 + return Err(format!(
512 + "Play stored version code {} with SHA-256 {}, but the local file is {expected}; \
513 + nothing was committed",
514 + uploaded.version_code, uploaded.sha256
515 + ));
516 + }
517 + if let Some(mapping) = mapping {
518 + c.upload_deobfuscation(package, id, uploaded.version_code, mapping)
519 + .await
520 + .map_err(err)?;
521 + }
522 + let code = uploaded.version_code.to_string();
523 + let track = c.get_track(package, id, track_name).await.map_err(err)?;
524 + let planned = track.place_uploaded(&code, status)?;
525 + c.update_track(package, id, &planned).await.map_err(err)?;
526 + Ok(uploaded.version_code)
527 + })
528 + })?;
529 + let track = read_track(client, package, track_name).await?;
530 + let code = version_code.to_string();
531 + let landed = bundle_landed(&track, &code, status);
532 + if !landed {
533 + return Err(format!(
534 + "committed, but {track_name} does not show version code {version_code} as {status}"
535 + ));
536 + }
537 + Ok(BundleUploaded {
538 + version_code,
539 + sha256: local_sha,
540 + status: status.to_string(),
541 + mapping_uploaded,
542 + track,
543 + })
544 +}
545 +
546 #[derive(Debug, Serialize)]
547 #[serde(rename_all = "camelCase")]
548 pub struct Promoted {
@@ -712,4 +880,63 @@ mod tests {
880 assert!(error.contains("PLAY_SERVICE_ACCOUNT_JSON_PATH"));
881 }
882 }
883 +
884 + fn zip_with(dir: &Path, name: &str, entries: &[&str]) -> PathBuf {
885 + let path = dir.join(name);
886 + let mut zip = zip::ZipWriter::new(std::fs::File::create(&path).unwrap());
887 + for entry in entries {
888 + zip.start_file(*entry, zip::write::SimpleFileOptions::default())
889 + .unwrap();
890 + std::io::Write::write_all(&mut zip, b"x").unwrap();
891 + }
892 + zip.finish().unwrap();
893 + path
894 + }
895 +
896 + #[test]
897 + fn load_bundle_accepts_a_bundle_and_rejects_the_rest() {
898 + let dir = std::env::temp_dir().join(format!("asc-aab-{}", std::process::id()));
899 + std::fs::create_dir_all(&dir).unwrap();
900 + let good = zip_with(&dir, "ok.aab", &[BUNDLE_MANIFEST]);
901 + let (file, bytes) = load_bundle(&good).unwrap();
902 + assert_eq!(file.bytes as usize, bytes.len());
903 + assert_eq!(file.sha256.len(), 64);
904 +
905 + let bare = zip_with(&dir, "bare.aab", &["other.txt"]);
906 + assert!(load_bundle(&bare)
907 + .unwrap_err()
908 + .contains("not an Android App Bundle"));
909 +
910 + let text = dir.join("a.aab");
911 + std::fs::write(&text, b"not a zip").unwrap();
912 + assert!(load_bundle(&text).unwrap_err().contains("not a zip"));
913 + assert!(load_bundle(&dir.join("missing.aab")).is_err());
914 +
915 + let missing_mapping = dir.join("nope.txt");
916 + assert!(plan_bundle_upload(
917 + "p",
918 + "internal",
919 + &good,
920 + "draft",
921 + Some(&missing_mapping),
922 + false
923 + )
924 + .unwrap_err()
925 + .contains("mapping file"));
926 + assert!(plan_bundle_upload("p", "internal", &good, "inProgress", None, false).is_err());
927 + let plan = plan_bundle_upload("p", "internal", &good, "draft", None, false).unwrap();
928 + assert!(plan.dry_run);
929 + std::fs::remove_dir_all(&dir).unwrap();
930 + }
931 +
932 + #[test]
933 + fn read_back_must_show_the_code_at_the_status() {
934 + let track: Track = serde_json::from_str(
935 + r#"{"track":"internal","releases":[{"versionCodes":["8"],"status":"draft"}]}"#,
936 + )
937 + .unwrap();
938 + assert!(bundle_landed(&track, "8", "draft"));
939 + assert!(!bundle_landed(&track, "8", "completed"));
940 + assert!(!bundle_landed(&track, "9", "draft"));
941 + }
942 }
crates/play/src/client.rs
+98
@@ -44,6 +44,41 @@ pub(crate) fn upload_path(package: &str, edit_id: &str, locale: &str, image: Ima
44 )
45 }
46
47 +/// `POST` target for `edits.bundles.upload`. `ack_install_warning` asks Play
48 +/// to accept a bundle it would otherwise refuse for an install-time warning.
49 +pub(crate) fn bundle_upload_path(
50 + package: &str,
51 + edit_id: &str,
52 + ack_install_warning: bool,
53 +) -> String {
54 + let ack = if ack_install_warning {
55 + "&ackBundleInstallationWarning=true"
56 + } else {
57 + ""
58 + };
59 + format!(
60 + "/upload/androidpublisher/v3/applications/{package}/edits/{edit_id}/bundles?uploadType=media{ack}"
61 + )
62 +}
63 +
64 +/// `POST` target for `edits.deobfuscationfiles.upload` (a ProGuard/R8
65 +/// mapping file for one uploaded version code).
66 +pub(crate) fn deobfuscation_path(package: &str, edit_id: &str, version_code: u64) -> String {
67 + format!(
68 + "/upload/androidpublisher/v3/applications/{package}/edits/{edit_id}/apks/{version_code}/deobfuscationFiles/proguard?uploadType=media"
69 + )
70 +}
71 +
72 +/// What Play reports for an uploaded bundle.
73 +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
74 +#[serde(rename_all = "camelCase")]
75 +pub struct UploadedBundle {
76 + pub version_code: u64,
77 + /// Lowercase hex SHA-256 of the bundle as Play received it.
78 + #[serde(default)]
79 + pub sha256: String,
80 +}
81 +
82 pub struct PlayClient {
83 http: reqwest::Client,
84 account: ServiceAccount,
@@ -249,6 +284,45 @@ impl PlayClient {
284 Ok(uploaded.image)
285 }
286
287 + /// Upload an `.aab` into the edit. The version code is assigned by Play
288 + /// from the bundle and consumed for good, even if the edit is later
289 + /// discarded.
290 + pub async fn upload_bundle(
291 + &self,
292 + package: &str,
293 + edit_id: &str,
294 + bytes: Vec<u8>,
295 + ack_install_warning: bool,
296 + ) -> Result<UploadedBundle> {
297 + let path = bundle_upload_path(package, edit_id, ack_install_warning);
298 + let response = self
299 + .send(
300 + Method::POST,
301 + &path,
302 + Some(("application/octet-stream", bytes)),
303 + )
304 + .await?;
305 + Ok(response.json().await?)
306 + }
307 +
308 + /// Attach a ProGuard/R8 `mapping.txt` to an uploaded version code.
309 + pub async fn upload_deobfuscation(
310 + &self,
311 + package: &str,
312 + edit_id: &str,
313 + version_code: u64,
314 + bytes: Vec<u8>,
315 + ) -> Result<()> {
316 + let path = deobfuscation_path(package, edit_id, version_code);
317 + self.send(
318 + Method::POST,
319 + &path,
320 + Some(("application/octet-stream", bytes)),
321 + )
322 + .await?;
323 + Ok(())
324 + }
325 +
326 /// Remove every image in a bucket; returns how many Play reports deleted.
327 pub async fn delete_all_images(
328 &self,
@@ -448,4 +522,28 @@ mod tests {
522 "/upload/androidpublisher/v3/applications/p/edits/E1/listings/en-US/phoneScreenshots?uploadType=media"
523 );
524 }
525 +
526 + #[test]
527 + fn bundle_upload_urls() {
528 + assert_eq!(
529 + bundle_upload_path("p", "E1", false),
530 + "/upload/androidpublisher/v3/applications/p/edits/E1/bundles?uploadType=media"
531 + );
532 + assert_eq!(
533 + bundle_upload_path("p", "E1", true),
534 + "/upload/androidpublisher/v3/applications/p/edits/E1/bundles?uploadType=media&ackBundleInstallationWarning=true"
535 + );
536 + assert_eq!(
537 + deobfuscation_path("p", "E1", 42),
538 + "/upload/androidpublisher/v3/applications/p/edits/E1/apks/42/deobfuscationFiles/proguard?uploadType=media"
539 + );
540 + }
541 +
542 + #[test]
543 + fn uploaded_bundle_parses_play_response() {
544 + let b: UploadedBundle =
545 + serde_json::from_str(r#"{"versionCode":7,"sha256":"ab12"}"#).unwrap();
546 + assert_eq!(b.version_code, 7);
547 + assert_eq!(b.sha256, "ab12");
548 + }
549 }
crates/play/src/lib.rs
+1 -1
@@ -16,7 +16,7 @@ pub mod product;
16 pub mod track;
17
18 pub use auth::ServiceAccount;
19 -pub use client::{Edit, PlayClient};
19 +pub use client::{Edit, PlayClient, UploadedBundle};
20 pub use error::{Error, Result};
21 pub use image::{png_dimensions, Image, ImageType};
22 pub use listing::{
crates/play/src/track.rs
+71
@@ -161,6 +161,48 @@ impl Track {
161 })
162 }
163
164 + /// Plan placing a freshly uploaded `version_code` on this track as a
165 + /// new release at `status` (`draft` or `completed`).
166 + ///
167 + /// Follows the same rule as [`Track::promote_from`]: an `inProgress` or
168 + /// `draft` release is replaced, `completed` ones stay. Unmodelled fields
169 + /// on releases that stay are untouched. The new release has no notes;
170 + /// `tracks set-notes` adds them afterwards.
171 + pub fn place_uploaded(
172 + &self,
173 + version_code: &str,
174 + status: &str,
175 + ) -> std::result::Result<Track, String> {
176 + if !matches!(status, "draft" | "completed") {
177 + return Err(format!(
178 + "status {status:?} is not supported for an upload; use draft or completed"
179 + ));
180 + }
181 + let release = TrackRelease {
182 + name: None,
183 + version_codes: vec![version_code.to_string()],
184 + status: Some(status.to_string()),
185 + user_fraction: None,
186 + release_notes: Vec::new(),
187 + country_targeting: None,
188 + extra: Default::default(),
189 + };
190 + let mut releases: Vec<TrackRelease> = self
191 + .releases
192 + .iter()
193 + .filter(|r| {
194 + !matches!(r.status.as_deref(), Some("inProgress") | Some("draft"))
195 + && !r.version_codes.iter().any(|c| c == version_code)
196 + })
197 + .cloned()
198 + .collect();
199 + releases.insert(0, release);
200 + Ok(Track {
201 + track: self.track.clone(),
202 + releases,
203 + })
204 + }
205 +
206 /// Plan `action` on the release carrying `version_code`. Only that
207 /// release changes; the others (the `completed` one serving users during
208 /// a staged rollout) are carried through. A fraction never goes down:
@@ -571,4 +613,33 @@ mod tests {
613 assert_eq!(t.max_version_code(), Some(2026110222));
614 assert_eq!(production("").max_version_code(), None);
615 }
616 +
617 + #[test]
618 + fn place_uploaded_replaces_draft_and_keeps_completed() {
619 + let t: Track = serde_json::from_str(
620 + r#"{"track":"internal","releases":[
621 + {"versionCodes":["5"],"status":"completed","futureField":{"a":1}},
622 + {"versionCodes":["6"],"status":"draft","releaseNotes":[{"language":"en-US","text":"x"}]},
623 + {"versionCodes":["7"],"status":"inProgress","userFraction":0.1}]}"#,
624 + )
625 + .unwrap();
626 + let out = t.place_uploaded("8", "draft").unwrap();
627 + assert_eq!(out.releases.len(), 2);
628 + assert_eq!(out.releases[0].version_codes, vec!["8"]);
629 + assert_eq!(out.releases[0].status.as_deref(), Some("draft"));
630 + assert!(out.releases[0].release_notes.is_empty());
631 + assert_eq!(out.releases[1].version_codes, vec!["5"]);
632 + assert!(out.releases[1].extra.contains_key("futureField"));
633 + }
634 +
635 + #[test]
636 + fn place_uploaded_on_an_empty_track_and_completed() {
637 + let t = Track {
638 + track: "production".into(),
639 + releases: vec![],
640 + };
641 + let out = t.place_uploaded("1", "completed").unwrap();
642 + assert_eq!(out.releases[0].status.as_deref(), Some("completed"));
643 + assert!(t.place_uploaded("1", "inProgress").is_err());
644 + }
645 }