Publish Kubb Studio snapshots from CI
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.
Prerequisites
- A working
kubb.config.tson Kubb 5.6.2 or later. See Installation. tsdownnext tokubbin the dev dependencies (npm i -D tsdown). Snapshots build theirdistfiles with it.- Two Studio API keys, created under Settings › Developers › Tokens:
| Key type | Store it as | Used for |
|---|---|---|
| CI | KUBB_TOKEN, in a secret only trusted pipelines can read | Publishing snapshots |
| Registry | KUBB_REGISTRY_TOKEN, which .npmrc reads | Installing a snapshot |
When the config exports an array, the snapshot packs every entry's output into one package.
Supported providers
| Provider | Agent identity | Compares with the base branch | Setup |
|---|---|---|---|
| GitHub Actions | Detected | Detected | GitHub Actions |
| GitLab CI | Detected | Detected | GitLab CI |
| Bitbucket Pipelines, CircleCI | Detected | Pass --base-id | Run kubb studio snapshot with KUBB_TOKEN set |
| Other | Pass --id | Pass --base-id | Other providers |
Other CI providers
Pass a stable --id on the base branch, and the same id as --base-id on pull request runs:
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 requestTo 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.
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.
//kubb.studio/:_authToken=${KUBB_REGISTRY_TOKEN}npm i https://kubb.studio/packages/<agent>/<package>.tgzYarn 1 also needs the registry for the package's scope, or the install fails with HTTP 403:
@<scope>:registry=https://kubb.studio/