Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

feat(build): add build upload for Android APK/AAB - #1172

Merged
BYK merged 2 commits into
mainfrom
byk/feat/build-upload-android
Jul 2, 2026
Merged

BYK merged 2 commits into
mainfrom
byk/feat/build-upload-android

Conversation

@BYK

@BYK BYK commented Jul 2, 2026

Copy link
Copy Markdown
Member

Second PR of the build/Emerge workstream (after build download #1170). Adds the flagship build upload for Android.

build upload <paths...>

Uploads mobile builds to Sentry for preprod size analysis.

  • Format detection (src/lib/build/): APK (root AndroidManifest.xml) and AAB (BundleConfig.pb + base/manifest/AndroidManifest.xml) via ZIP entry names — no decompression. IPA is detected only to emit a clear "iOS not yet supported" message.
  • Normalization: wraps each build into a deterministic ZIP (build under its basename + .sentry-cli-metadata.txt) using STORE + fixed mtime via fflate. Deterministic bytes let the server dedup chunks across re-uploads.
  • Upload (uploadBuild in preprod-artifacts.ts): chunk-upload (reusing chunk-upload.ts) + the single-object projects/{org}/{project}/files/preprodartifacts/assemble/ endpoint, polling until the server returns artifactUrl (5-min cap, 1s poll).
  • Multiple paths with per-file success/error aggregation; exits non-zero if any build fails. --build-configuration, --release-notes, repeatable --install-group fold into the assemble body.
  • Org+project resolved from context/flags/env. Sentry SaaS only.

Why not zstd-in-zip (matching the legacy CLI)?

Node's built-in zstd is raw-stream only; Zstd inside a ZIP needs a writer emitting method-93 entries, which the JS ZIP libs don't do. It also buys nothing here: the wrapper's method is transparent to the server (it just unzips), the inner APK/AAB is already compressed (so STORE avoids pointless double-compression), and dedup determinism comes from the fixed mtime, not the method. Transport already compresses chunks over the wire.

Tests (33 across 3 files)

  • build/index.test.ts — APK/AAB/IPA detection, plugin parsing, normalization determinism + contents.
  • preprod-artifacts.test.ts — uploadBuild assemble-body shape, missing-chunk→upload→artifactUrl (fake timers), error → ApiError.
  • build/upload.test.ts — APK upload, metadata pass-through, unsupported-file + directory rejection, partial-failure exit code.

Follow-ups (not in this PR)

git/VCS metadata + CI auto-detect; iOS XCArchive/IPA upload (.car asset parsing is native-macOS-only and skipped); snapshots (download/diff now, upload in the objectstore session).

typecheck, lint, check:deps, check:fragments all pass.

Ports the Android path of `sentry-cli build upload`. Detects APK/AAB from ZIP
entry names, wraps each build into a deterministic normalized ZIP (STORE + fixed
mtime, via fflate — no new deps, no double-compression), and uploads it through
the chunk-upload + single-object `preprodartifacts/assemble/` endpoint, polling
until the server returns the assembled `artifactUrl`.

Supports multiple paths with per-file success/error aggregation and a non-zero
exit when any build fails. `--build-configuration`, `--release-notes`, and
repeatable `--install-group` are folded into the assemble body.

iOS XCArchive/IPA is detected and rejected with a clear "not yet supported"
message (ported separately); git/VCS metadata is a follow-up. Sentry SaaS only.
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1172/

Built to branch gh-pages at 2026-07-02 15:48 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 93.22%. Project has 5145 uncovered lines.
✅ Project coverage is 81.61%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
src/commands/build/upload.ts 88.89% ⚠️ 5 Missing and 4 partials
src/lib/api/preprod-artifacts.ts 96.77% ⚠️ 1 Missing and 1 partials
src/lib/build/index.ts 95.24% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.56%    81.61%    +0.05%
==========================================
  Files          402       404        +2
  Lines        27859     27978      +119
  Branches     18105     18176       +71
==========================================
+ Hits         22723     22833      +110
- Misses        5136      5145        +9
- Partials      1865      1870        +5

Generated by Codecov Action

Self-review findings:
- C1 (critical): `--install-group` was accidentally required (variadic without
  `optional: true`), breaking the primary `build upload <path>` invocation. Add
  `optional: true` and a parser-level regression test (the loader() tests bypass
  Stricli arg parsing, so they missed it).
- L3: fail fast on a terminal `ok` assemble state without an artifactUrl instead
  of polling to the deadline (matches the legacy loop).
- L1: document the deliberate STORE-vs-legacy-Zstd normalization choice.
- M1: clarify that exiting non-zero on partial failure is a deliberate deviation
  from the legacy CLI (fail loud for CI/agents).
- M2: note the in-memory (readFile) large-build ceiling as a follow-up.
- Add tests: assemble body omits empty metadata fields; ok-without-url throws.
@BYK

BYK commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Self-review (subagent-assisted) + fixes

Ran a critical review against the legacy Rust source. Key outcome:

Critical (fixed): --install-group was accidentally required (variadic without optional: true), so the primary build upload <path> invocation failed at parse time. Fixed + added a parser-level regression test — the previous command tests drove the command via loader(), which bypasses Stricli arg parsing, so they couldn't see it. New test runs through run(app, …).

Also fixed: fail-fast on a terminal ok assemble state without artifactUrl (L3, matches legacy); tests for empty-metadata body omission and the ok-without-url throw.

Two deliberate deviations from the legacy Rust CLI (flagging for visibility):

  1. Partial-failure exit code — legacy exits 0 when some builds upload and others fail; this port exits non-zero on any failure so CI/agents don't mistake a partial upload for success. (Comment updated to state this.)
  2. Wrapper compression — legacy uses Zstd-in-ZIP; this uses STORE + fixed mtime (APK/AAB are already compressed; avoids a method-93 ZIP writer; deterministic for dedup within this CLI). Documented in src/lib/build/index.ts.

Known follow-up: builds are read fully into memory (readFile), so files above Node's ~2 GiB Buffer cap will throw where the legacy mmap path succeeds. Noted in-code; a streaming-normalization follow-up can use the file-based chunk path.

@BYK
BYK merged commit bbc0b93 into main Jul 2, 2026
42 of 44 checks passed
@BYK
BYK deleted the byk/feat/build-upload-android branch July 2, 2026 16:03
BYK added a commit that referenced this pull request Jul 2, 2026
Third PR of the **build/Emerge** workstream (after `build download`
#1170, `build upload` #1172). Brings `build upload` to VCS parity and
lays the groundwork `snapshots` will reuse.

## What
`build upload` now attaches VCS metadata to the assemble request. Per
the server's flattened `VcsInfo`, these are **top-level** body fields
(omit-if-empty): `head_sha`, `base_sha`, `provider`, `head_repo_name`,
`base_repo_name`, `head_ref`, `base_ref`, `pr_number`.

**Precedence (mirrors the legacy `collect_git_metadata`):**
- **Explicit flags always win:** `--head-sha`, `--base-sha`,
`--vcs-provider`, `--head-repo-name`, `--base-repo-name`, `--head-ref`,
`--base-ref`, `--pr-number`.
- **Auto-collection** runs in CI (unless `--no-git-metadata`) or when
`--force-git-metadata` is set:
- GitHub Actions env: `GITHUB_HEAD_REF`/`GITHUB_BASE_REF`
(pull_request), `GITHUB_REPOSITORY`, PR number from `GITHUB_REF`
(`refs/pull/N/merge`), head ref from `GITHUB_REF_NAME` for pushes.
- Local git: HEAD sha, current branch, remote → provider + repo name,
and a best-effort `merge-base` for `base_sha`.
- Base is dropped when it equals head and both were auto-inferred
(meaningless comparison), matching legacy.

## Files
- `src/lib/build/vcs.ts` — `collectVcsMetadata`, `isCi`, `vcsInfoToBody`
(per-field resolver helpers keep complexity low).
- `src/lib/git.ts` — additive helpers: `getRemoteUrl`,
`getCurrentBranch`, `getMergeBase` (execFile, no shell; match the
module's existing style).
- `src/lib/api/preprod-artifacts.ts` — `BuildUploadMetadata.vcs`
flattened into the assemble body.
- `src/commands/build/upload.ts` — 10 git flags + collection wired in.
- Tests (15 new): flag precedence, GitHub Actions PR inference,
base==head skip, `vcsInfoToBody` mapping, and a command-level assertion
that flags reach the body.

## Notes / follow-ups
- `base_repo_name` fork auto-detection and non-GitHub CI providers are
not yet inferred (explicit flags still work); a follow-up can extend
inference. `base_sha` auto-inference is best-effort (skipped on shallow
clones / unknown refs).

`typecheck`, `lint`, `check:deps`, `check:fragments` all pass.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
BYK added a commit that referenced this pull request Jul 2, 2026
Fourth PR of the **build/Emerge** workstream (after `build download`
#1170, `build upload` #1172, VCS metadata #1174). Establishes the
**`snapshots`** command group and its first subcommand.

## `snapshots download`
Downloads baseline snapshot images from Sentry's preprod system and
extracts them locally. **Sentry SaaS only.**

- **Resolve the snapshot**: `--snapshot-id <id>` (direct) or `--app-id
<app>` → latest baseline (optional `--branch`; `--project` numeric ID
for org auth tokens). The two ID flags are mutually exclusive;
`--branch` requires `--app-id`.
- **Ensure the archive is built**: checks status, and if not ready
triggers a build and polls (2s interval, 5-min timeout via
`TimeoutError`).
- **Download + extract**: downloads the archive ZIP and extracts images
to `--output` (default `./snapshots-base/`), with **Zip-Slip
protection** (entries escaping the output dir are skipped).

## Files
- `src/lib/api/preprod-artifacts.ts` — `getLatestBaseSnapshot` (404 →
`null`), `getSnapshotArchiveReady`, `triggerSnapshotArchiveBuild`,
`waitForSnapshotArchive`, `downloadSnapshotArchive` (auth dropped
cross-origin on the storage redirect).
- `src/lib/snapshots/archive.ts` — `extractZipToDir` (fflate,
path-traversal safe).
- `src/commands/snapshots/{download,index}.ts` + `app.ts` registration.
- Tests (11 new): extraction incl. Zip-Slip; API incl. 404→null and
trigger→poll→ready; command flag validation + app-id resolution + real
extraction.

## Follow-ups (not in this PR)
`snapshots diff` (needs an image-diff dependency decision — native
`odiff` vs pure-JS); `snapshots upload` (blocked on the objectstore
session).

`typecheck`, `lint`, `check:deps`, `check:fragments` all pass.
BYK added a commit that referenced this pull request Jul 3, 2026
Extends `build upload` (Android APK/AAB, PRs #1172/#1174) to **iOS** —
XCArchive and IPA.

## What
- **XCArchive** (a directory): zipped under its basename
(`MyApp.xcarchive/…`) + a root `.sentry-cli-metadata.txt`, mirroring the
legacy `normalize_directory`.
- **IPA** (a file): converted **in-memory** to an XCArchive layout —
`Payload/<app>.app/…` →
`archive.xcarchive/Products/Applications/<app>.app/…` plus a generated
`archive.xcarchive/Info.plist` — mirroring `ipa_to_xcarchive` +
`normalize_directory`. Requires exactly one `.app`.

Both use STORE + a fixed mtime so identical inputs produce identical
bytes (chunk dedup on re-upload).

## Cross-platform (intentional divergence from the Rust CLI)
The legacy CLI gated iOS to **Apple Silicon** solely because
`handle_asset_catalogs` parses `Assets.car` via native macOS CoreUI
(`apple_catalog_parsing`). Per the agreed scope we **skip `.car`
parsing**, and with that removed the entire iOS path (`ipa_to_xcarchive`
is pure zip + a static plist string; `normalize_directory` is a plain
directory walk) is portable — so iOS upload ships on **all platforms**,
no Apple-Silicon gate.

## Documented limitations
- No `Assets.car` asset-catalog parsing → server sees the raw `.car`,
not a per-image breakdown.
- Directory symlinks are followed and stored as target content (not
preserved as symlink entries); Unix permissions are not preserved (a
`zipSync` limitation). iOS `.app` bundles are typically flat, so this is
rarely material.
- In-memory normalization (same as the Android path) — a very large
XCArchive with dSYMs could hit Node's ~2 GiB Buffer cap;
streaming-to-temp-file is a noted follow-up.

## Tests
Lib: XCArchive dir → zip structure + determinism; IPA → XCArchive
structure + generated Info.plist + `Assets.car` passed through verbatim;
`extractIpaAppName` for 0/1/≥2 `.app`. Command: XCArchive directory +
IPA both reach `uploadBuild`; obsolete "not supported" cases replaced.

`typecheck`, `lint`, `check:deps`, `check:fragments` pass; 44 build
tests pass.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant