Repository navigation
ci(api-docs): Build the @sentry/api client from the PR's API schema - #130450
sentry-junior[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: BYK <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
BYK
left a comment
There was a problem hiding this comment.
Instead of this, how hard would it be to move @sentry/api into this repo instead?
|
Doable, and getsentry/sentry already has the pattern.
We're going with the move instead of this stopgap, so I'm closing this PR. |
…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>

getsentry/sentry-api-schema turns the
openapi-derefed.jsonbuilt here into the@sentry/apinpm package. Two schema changes merged to master in November broke that package's build:createSentryClient's inferred type got too large to emit (TS7056).format: uint64integers made the Zod output callBigInt(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-buildjob toopenapi-diff.yml. It runs only whencheck-diffbuilt the schema, so it has the sameapi_docspath filter.check-diffnow uploads the builtopenapi-derefed.jsonas an artifact, right after building it. The new job:main.pnpm install --frozen-lockfile,pnpm build(normalize, generate, bundle and declarations),pnpm typecheckandpnpm 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/apireleases until the generator handles it.Reproduction
I ran the job's steps locally, using sentry-api-schema code from before #136 (8234586):
pnpm buildfails withTS7056insrc/sentry-client.gen.ts.pnpm buildfails withzod.gen.ts: unexpected top-level call outside z.*: BigInt(0).mainand the current master schema: build, typecheck and test all pass.This PR changes only the workflow file, which isn't in the
api_docsfilter. The new job therefore runs on the next PR that touches API docs, not on this one.actionlintpasses on the changed workflow. Its only report is the existingubuntu-26.04-armrunner 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