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

feat(build): add build download command for preprod artifacts - #1170

Merged
BYK merged 1 commit into
mainfrom
byk/feat/build-download
Jul 2, 2026
Merged

BYK merged 1 commit into
mainfrom
byk/feat/build-download

Conversation

@BYK

@BYK BYK commented Jul 2, 2026

Copy link
Copy Markdown
Member

First PR of the build/Emerge workstream (porting sentry-cli build/snapshots from the legacy Rust CLI). Establishes the new build command group + a preprod-artifacts API 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.

  • Resolves the download URL via the org-scoped organizations/{org}/preprodartifacts/{id}/install-details/ endpoint.
  • Rewrites an iOS response_format=plist manifest URL to response_format=ipa to fetch the actual binary; infers the format (ipa/apk).
  • Streams the artifact to preprod_artifact_<build-id>.<ext> (or --output/-o). Large artifacts stream to disk — never buffered in memory.
  • Org-scoped (no project); resolved from --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 — new build route group + download command.
  • src/app.ts — register the build route.
  • docs/src/fragments/commands/build.md + regenerated skill/contributing docs.
  • Tests: 13 (pure URL helpers, getBuildInstallDetails endpoint 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 upload is an objectstore command (deferred to the objectstore session); iOS .car asset parsing is native-macOS-only and intentionally skipped.

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

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).
@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-1170/

Built to branch gh-pages at 2026-07-02 14:06 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.02%. Project has 5139 uncovered lines.
✅ Project coverage is 81.55%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/commands/build/download.ts 94.12% ⚠️ 1 Missing and 1 partials
src/lib/api/preprod-artifacts.ts 92.00% ⚠️ 2 Missing
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        +1

Generated by Codecov Action

@BYK
BYK merged commit 57a003b into main Jul 2, 2026
30 checks passed
@BYK
BYK deleted the byk/feat/build-download branch July 2, 2026 14:15
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.
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