Repository navigation
feat(build): add build upload for Android APK/AAB - #1172
Conversation
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.
|
Codecov Results 📊✅ Patch coverage is 93.22%. Project has 5145 uncovered lines. Files with missing lines (3)
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 +5Generated 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.
Self-review (subagent-assisted) + fixesRan a critical review against the legacy Rust source. Key outcome: Critical (fixed): Also fixed: fail-fast on a terminal Two deliberate deviations from the legacy Rust CLI (flagging for visibility):
Known follow-up: builds are read fully into memory ( |
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>
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.
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.
Second PR of the build/Emerge workstream (after
build download#1170). Adds the flagshipbuild uploadfor Android.build upload <paths...>Uploads mobile builds to Sentry for preprod size analysis.
src/lib/build/): APK (rootAndroidManifest.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..sentry-cli-metadata.txt) using STORE + fixed mtime viafflate. Deterministic bytes let the server dedup chunks across re-uploads.uploadBuildinpreprod-artifacts.ts): chunk-upload (reusingchunk-upload.ts) + the single-objectprojects/{org}/{project}/files/preprodartifacts/assemble/endpoint, polling until the server returnsartifactUrl(5-min cap, 1s poll).--build-configuration,--release-notes, repeatable--install-groupfold into the assemble body.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—uploadBuildassemble-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 (
.carasset parsing is native-macOS-only and skipped);snapshots(download/diffnow,uploadin the objectstore session).typecheck,lint,check:deps,check:fragmentsall pass.