Skip to content
Integrations

Publish Kubb Studio snapshots from CI

Run kubb studio snapshot in GitHub Actions, GitLab CI, or any CI to publish an installable package of your generated code per pull request.

A snapshot is an installable npm package of your generated code. kubb studio snapshot builds it on the CI runner, uploads it to Studio, and exits.

Run it on pull or merge requests and on their base branch, so each request has a snapshot to compare with.

packagePull requestCI jobkubb studio snapshotKubb StudioReview filesnpm install

Prerequisites

  • A working kubb.config.ts on Kubb 5.6.2 or later. See Installation.
  • tsdown next to kubb in the dev dependencies (npm i -D tsdown). Snapshots build their dist files with it.
  • Two Studio API keys, created under Settings › Developers › Tokens:
Key typeStore it asUsed for
CIKUBB_TOKEN, in a secret only trusted pipelines can readPublishing snapshots
RegistryKUBB_REGISTRY_TOKEN, which .npmrc readsInstalling a snapshot

When the config exports an array, the snapshot packs every entry's output into one package.

Supported providers

ProviderAgent identityCompares with the base branchSetup
GitHub ActionsDetectedDetectedGitHub Actions
GitLab CIDetectedDetectedGitLab CI
Bitbucket Pipelines, CircleCIDetectedPass --base-idRun kubb studio snapshot with KUBB_TOKEN set
OtherPass --idPass --base-idOther providers

Other CI providers

Pass a stable --id on the base branch, and the same id as --base-id on pull request runs:

Terminal
kubb studio snapshot --id jenkins:api:main                              # on main
kubb studio snapshot --id jenkins:api:pr-12 --base-id jenkins:api:main  # on a pull request

To pass the tarball URL to another step, run kubb studio snapshot --json | jq -r '.url'. See CI agent identity and Snapshot output for every field.

Review the snapshot

Studio has no diff view for snapshots. The GitHub Action lists the changed files in its comment, and --json reports them in changes and branchChanges on any provider.

After the runner exits, open the CI agent's editor in Studio to read its latest unexpired package, comment on source lines, or preview generated HTML. Run the pipeline again to publish new output.

Snapshots expire after seven days. If the default branch can go a week without a push, schedule a run.

Install the snapshot

Add the registry key to .npmrc, then run the install command from the snapshot result. pnpm and Yarn use the same URL and .npmrc.

.npmrc
//kubb.studio/:_authToken=${KUBB_REGISTRY_TOKEN}
Terminal
npm i https://kubb.studio/packages/<agent>/<package>.tgz

Yarn 1 also needs the registry for the package's scope, or the install fails with HTTP 403:

.npmrc
@<scope>:registry=https://kubb.studio/