This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Repository navigation
feat(build): add build download command for preprod artifacts - #1170
Merged
Merged
Conversation
Ports `sentry-cli build download` from the legacy Rust CLI. Establishes the
new `build` command group and a `preprod-artifacts` API module.
`build download <build-id>` resolves the build's install/download URL via the
org-scoped `preprodartifacts/{id}/install-details/` endpoint, rewrites an iOS
plist manifest URL to fetch the IPA binary, infers the format (ipa/apk), and
streams the artifact to `preprod_artifact_<build-id>.<ext>` (or `--output`).
The download attaches the auth token only when the URL shares the org region's
origin, so it is never leaked to a third-party/signed storage URL. Large
artifacts stream to disk (never buffered in memory).
Contributor
|
Contributor
Codecov Results 📊✅ Patch coverage is 93.02%. Project has 5139 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.55% 81.55% —%
==========================================
Files 399 402 +3
Lines 27815 27859 +44
Branches 18081 18105 +24
==========================================
+ Hits 22683 22720 +37
- Misses 5132 5139 +7
- Partials 1865 1866 +1Generated by Codecov Action |
BYK
added a commit
that referenced
this pull request
Jul 2, 2026
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.
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.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First PR of the build/Emerge workstream (porting
sentry-cli build/snapshotsfrom the legacy Rust CLI). Establishes the newbuildcommand group + apreprod-artifactsAPI module, starting with the lowest-risk, self-contained subcommand.build download <build-id>Downloads a mobile build artifact (APK/IPA) previously uploaded to Sentry's preprod system for size analysis.
organizations/{org}/preprodartifacts/{id}/install-details/endpoint.response_format=plistmanifest URL toresponse_format=ipato fetch the actual binary; infers the format (ipa/apk).preprod_artifact_<build-id>.<ext>(or--output/-o). Large artifacts stream to disk — never buffered in memory.--org/SENTRY_ORG/config/DSN. Sentry SaaS only.Security note
The download attaches the auth token only when the URL shares the org region's origin, so it is never leaked to a third-party/signed storage URL (mirrors the CLI's existing signed-download handling). Covered by tests.
Files
src/lib/api/preprod-artifacts.ts—getBuildInstallDetails,toBinaryDownloadUrl,buildFormatFromUrl,downloadBuildArtifact(origin-gated auth + streaming).src/commands/build/{index,download}.ts— newbuildroute group +downloadcommand.src/app.ts— register thebuildroute.docs/src/fragments/commands/build.md+ regenerated skill/contributing docs.getBuildInstallDetailsendpoint shape, streaming download, auth-origin gating same/cross-origin/no-token, non-2xx →ApiError, and command orchestration incl. not-installable guard).Follow-ups (tracked, not in this PR)
build upload(Android APK/AAB via chunk-upload), git/VCS metadata,snapshots download/diff.snapshots uploadis an objectstore command (deferred to the objectstore session); iOS.carasset parsing is native-macOS-only and intentionally skipped.typecheck,lint,check:deps,check:fragmentsall pass.