Skip to content
Integrations

Publish Kubb snapshots with GitHub Actions

Add the kubb-labs/action workflow to publish a Kubb Studio snapshot on each pull request and compare generated files with the base branch and the previous run.

Publish an installable Kubb Studio snapshot from GitHub Actions so reviewers can compare generated files against the base branch and previous runs. Store KUBB_TOKEN as an Actions repository secret.

Prerequisites

  • A repository with a working kubb.config.ts on Kubb 5.6.2 or later. Follow Installation if you have not set up Kubb.
  • A Kubb Studio organization and an organization CI API key, stored as KUBB_TOKEN in a secret only trusted pipelines can read. Snapshot installation uses a separate registry key. Create both in Studio under Settings › Developers › Tokens, with type CI for KUBB_TOKEN and type Registry for installs.
  • tsdown in the development dependencies, next to kubb, so npm ci installs it. A snapshot builds its dist files with it, and Kubb does not install it by default: npm i -D tsdown.

Configure the workflow

Add this workflow:

.github/workflows/kubb.yml
name: Kubb snapshot

on:
  pull_request:
    # `closed` deletes the pull request's Studio agent. GitHub leaves it out by default.
    types: [opened, synchronize, reopened, closed]
  # A snapshot of main is what pull requests compare with.
  push:
    branches: [main]

permissions:
  contents: write
  pull-requests: write

jobs:
  snapshot:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: kubb-labs/action@v0
        with:
          token: ${{ secrets.KUBB_TOKEN }}

pull-requests: write allows snapshot comments. contents: write lets the action open an initialization pull request when the repository has no Kubb config. For that pull request, turn on Allow GitHub Actions to create and approve pull requests under Settings > Actions > General.

Review the pull request comment for generated changes against the base branch and the previous run.

To pass the tarball URL to another step, give the action an id: snapshot, then read ${{ steps.snapshot.outputs.tarball-url }}. See the action reference for all inputs, outputs, and runtime behavior.

Review and install the result

Studio has no diff view for snapshots. The GitHub Action lists the changed generated files in its pull request comment, and kubb studio snapshot --json reports them in changes and branchChanges with any provider. To consume the generated package, follow Install the snapshot.

Snapshots expire after seven days. Schedule a default-branch run if it can go a week without a push.