Skip to content

ci(api-docs): Build the @sentry/api client from the PR's API schema - #130450

Closed
sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/openapi-client-build-check
Closed

sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/openapi-client-build-check

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

getsentry/sentry-api-schema turns the openapi-derefed.json built here into the @sentry/api npm package. Two schema changes merged to master in November broke that package's build:

  • After dc25434f, createSentryClient's inferred type got too large to emit (TS7056).
  • After 4260bab8, format: uint64 integers made the Zod output call BigInt(0), which the tree-shaking check rejects.

Nothing on the sentry side noticed. Releases stopped for 2 days, until getsentry/sentry-api-schema#136 fixed the generator.

This PR adds a client-build job to openapi-diff.yml. It runs only when check-diff built the schema, so it has the same api_docs path filter. check-diff now uploads the built openapi-derefed.json as an artifact, right after building it. The new job:

  1. Checks out sentry-api-schema main.
  2. Downloads the schema into it.
  3. Runs the same steps as that repo's Build workflow: pnpm install --frozen-lockfile, pnpm build (normalize, generate, bundle and declarations), pnpm typecheck and pnpm test.

It uses Node 22, the oldest version the package supports and the one its release artifact is built with. It caches the pnpm store. In sentry-api-schema's CI these steps take about 3 minutes.

The job is not required. Its name starts with "(Optional)", like check-diff, and it isn't in master's required checks. A red result means that merging this schema as-is would block @sentry/api releases until the generator handles it.

Reproduction

I ran the job's steps locally, using sentry-api-schema code from before #136 (8234586):

  • With the schema from dc25434f: pnpm build fails with TS7056 in src/sentry-client.gen.ts.
  • With the current master schema: pnpm build fails with zod.gen.ts: unexpected top-level call outside z.*: BigInt(0).
  • With current sentry-api-schema main and the current master schema: build, typecheck and test all pass.

This PR changes only the workflow file, which isn't in the api_docs filter. The new job therefore runs on the next PR that touches API docs, not on this one. actionlint passes on the changed workflow. Its only report is the existing ubuntu-26.04-arm runner label, which actionlint doesn't know yet.

No UI changes, so no screenshots. Nothing for admins to set up: the job reads the public sentry-api-schema repo with the default token.

via @BYK.

--

View Session in Sentry

@sentry-junior
sentry-junior Bot requested a review from a team as a code owner November 9, 2026 16:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d66fdb9. Configure here.

Comment thread .github/workflows/openapi-diff.yml Resolved
@mchen-sentry mchen-sentry added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Nov 9, 2026

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, how hard would it be to move @sentry/api into this repo instead?

@sentry-junior

sentry-junior Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Doable, and getsentry/sentry already has the pattern. static/packages/* (scraps, icons, search-syntax) publish to npm through craft workspaces, with <name>@x.y.z tags, a Package pack artifact job and getsentry/publish. I'd estimate a few days rather than a quick move:

  • Easy: copy the package (lib/, test/, build.mjs, tsconfigs, about 145 files) to static/packages/api, and point build.mjs at tests/apidocs/openapi-derefed.json. The pre-merge breakage check then happens on its own in the same PR, so this PR goes away.
  • Spec build is heavy: package-pack.yml only runs pnpm install and pnpm pack, but the package's build needs the 15 MB derefed spec. That comes from make build-api-docs, which needs the full setup-sentry Python environment, so packing gets much slower.
  • Release cadence: sentry's release.yml only runs when dispatched. @sentry/api currently releases on every sync: about 151 releases and 167 Generated commits in the last 30 days. Each craft release merges a release branch back into master, and every one of those merges runs full CI. You'd want batched releases, say daily, or a way to publish without merging back.
  • Toolchain: sentry uses TypeScript 6, jest and oxlint, and its esbuild and zod versions differ from the package's. The package uses typescript ^5.9, vitest 5 and esbuild ^0.28.2. It would either align or pin its own versions, and knip and the lint rules would cover it.
  • Keep sentry-api-schema for the spec: sentry-docs pins a sentry-api-schema commit and reads the spec from it through "Bump API Schema SHA".

We're going with the move instead of this stopgap, so I'm closing this PR.

@sentry-junior sentry-junior Bot closed this Nov 9, 2026
BYK added a commit that referenced this pull request Nov 14, 2026
…0472)

Moves `@sentry/api`, the generated TypeScript client for Sentry's public
API, from getsentry/sentry-api-schema to `static/packages/api`. It
builds from `tests/apidocs/openapi-derefed.json`, the spec this
repository generates. The npm name stays `@sentry/api`, so
getsentry/toolkit, sentry-docs and other consumers don't change. This PR
replaces the pre-merge check from #130450, which was closed.

This PR doesn't publish anything. Releases from here stay off until a
person cuts the first `api@` tag (see the cutover section).

## Package

- The sources match getsentry/sentry-api-schema `main` at 2.3.1,
including the `@sentry/api/docs` API reference export
(getsentry/sentry-api-schema#150), the `listPage` `per_page` fix
(getsentry/sentry-api-schema#149) and `insufficient_scope` handling on
`ApiPermissionError` (getsentry/sentry-api-schema#146).
- One deliberate difference from sentry-api-schema `main`: the generated
`buildUrl` trims trailing slashes from the base URL before appending
`/api/0` (`withApiBasePath` in `lib/api-client/api-base-url.ts`), so
`https://sentry.io/` no longer requests `https://sentry.io//api/0`.
Published 2.x versions keep that bug; the fix ships with the first
`api@` release from here.
- `package.json` is at 2.3.1, the latest npm version. Craft bumps from
it while there is no `api@` tag, so the first release from here lands
after sentry-api-schema's.
- Differences from sentry-api-schema, all because of where the package
now lives:
- TypeScript 6 through the repo's `@typescript/typescript6` alias, and
zod 4.6.7, the version `static/app`, gsApp, gsAdmin and scraps already
pin. The other dev tools are pinned to exact versions, and oxlint
matches the repo's 1.90.0.
- The build reads the spec files through `lib/spec-files.mjs` and
collects them under `spec/`.
- `source-analysis` uses a path-parameter pattern that can't backtrack
on runs of `{`, for a CodeQL alert the move raised.
- The scripts are `test:vitest` and `lint:js`, not `test` and `lint`.
The repo's `test-ci` and `test-all` pass Jest flags to every workspace's
`test` script, and the repo's `lint:js` runs each workspace's `lint:js`.

## Spec files on GitHub releases

Each `[email protected]` GitHub release gets the files that version was built
from as assets. The pack job adds them to the release artifact; craft's
github target attaches every file in it, and its npm target publishes
only the tarball:

- `openapi-derefed.json`, the dereferenced OpenAPI spec.
- `rpc_method_schema.json`, for the openapi-diff/RPC check. It comes
from a new `make build-rpc-schema` target.
- `api_ownership_stats_dont_modify.json`, which `make build-api-docs`
still generates. No known consumer reads it; it is kept for ad-hoc and
future use.

For example:
`https://github.com/getsentry/sentry/releases/download/[email protected]/openapi-derefed.json`.
The npm package doesn't include them.

## CI: `api client` is a required check

The new `api-client` job in `backend.yml` builds, typechecks, lints and
tests the client against the PR's own spec. It is part of
`backend-required-check`. A spec change that broke the client once
stalled releases for 2 days with nothing catching it before merge; this
check catches that class of change.

- It reuses the spec from the `api-docs` job (shared as a workflow
artifact), so the spec isn't built twice.
- Both jobs run only when the new `api_client` filter matches: the
existing `api_docs` paths plus `static/packages/api/**`. On other PRs
both jobs are skipped, and `backend-required-check` counts skipped jobs
as passing.

## Releases

- **Pack:** `package-pack.yml` sets up the Python env for `api`, then
builds the spec, the RPC schema and the package before `pnpm pack`.
- **Release on change:** a `release-api-package` job in `openapi.yml`
runs after the master spec build whenever the spec or the package might
have changed. It runs
`.github/workflows/scripts/api-package-release-preflight.sh`, then
`craft prepare` with `getsentry/publish`. The preflight skips the
release when:
- there is no `api@` tag yet, so the job stays inert until the first
release is cut by hand;
- an `api/release/*` branch is still pending. When that release merges
back, its own run releases whatever landed in the meantime;
  - HEAD predates the newest `api@` tag;
- the spec, the RPC schema and the package are unchanged since the last
release. It compares the files against the last release's assets.
- **Version bump:** a spec change is a minor release, as in
sentry-api-schema. A package change uses craft's automatic bump. An
RPC-schema-only change is a patch. An ownership-stats-only change
doesn't release; the file refreshes with the next release.
- **Concurrency:** releases share a concurrency group with
`cancel-in-progress: false`, so a burst of merges produces one release.
- There is no cron. Manual releases go through the Release workflow,
which gets a `static/packages/api` option.
- **sentry-docs:** `bump-sentry-docs.yml` runs on each published `api@`
release. `.craft.yml` lists the npm target before github for
`static/packages/*`, so the version is already on npm when the release
is published (the same order applies to icons, scraps and search-syntax,
and nothing in them needs the tag before the npm publish). It dispatches
sentry-docs' `bump-api-schema-sha.yml` by file name with the existing
`SENTRY_API_SCHEMA_UPDATER` app. sentry-docs' bump reads the version
from npm, so it works the same after the move.
- The mirror push to getsentry/sentry-api-schema still runs, on the same
`api_client` filter, and the release doesn't wait for it.

## Cutover (in this order)

1. Merge #130541 and getsentry/eng-pipes#1116, which retires the `apis`
command. #130541 falls back to sentry-api-schema `main` until an `api@`
release exists.
2. Merge this PR.
3. In getsentry/publish `auto-approve-repos.txt`, replace the
`getsentry/sentry-api-schema` line with this repo's
`static/packages/api` entry.
4. Disable sentry-api-schema's Release workflow and its sentry-docs
dispatch workflow (getsentry/sentry-api-schema#155), so only one repo
publishes.
5. Cut the first `api@` release by hand: run the Release workflow with
workspace `static/packages/api`. Check that the version it picks is
above sentry-api-schema's last npm release. From then on, `openapi.yml`
releases on change.
6. Remove the openapi-diff fallback, the mirror push in `openapi.yml`,
and the sentry-api-schema links in the getsentry/toolkit docs,
getsentry/skills `document-api-endpoint` and devinfra-mcp
`docs/sentry/ci.md`.
7. Archive getsentry/sentry-api-schema. Its copies of the
`SENTRY_API_SCHEMA_UPDATER_*` credentials can go with it.

`static/packages/api/` is owned by @getsentry/owners-api and
@getsentry/ocpo in CODEOWNERS.

This PR touches `static/` as well as backend CI files. The package is a
standalone npm package and isn't part of either deploy, so splitting it
wouldn't change what gets deployed.

No UI change.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A69da19b385017e68b7f9eace56e9477f -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A69da19b385017e68b7f9eace56e9477f)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A69da19b385017e68b7f9eace56e9477f/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants