Nikasa, home Request an invite
DocsGitHub Actions

GitHub Actions

One Action step compares two images and puts the report on the pull request, in the job summary and in an artifact.

On this page

This page adds Nikasa to a GitHub Actions workflow as one step. The step compares two images, then puts the report on the pull request, in the job summary and in an artifact.

You need:

  • two images already built or pulled on the runner, your new build and your old one;
  • the app file, nk/app.yaml, committed (nk init drafts it);
  • the token from your invite, kept as a repository secret.

The words sandbox, compare, run and driver are defined at the top of Get started.

The step #

yaml
- uses: <nikasa-repo>@v0.3.14
  with:
    version: 0.3.14
    # The token from your invite, kept as a repository secret.
    token: ${{ secrets.NK_RELEASE_TOKEN }}
    old: app:old
    new: app:new
    app: nk/app.yaml

<nikasa-repo> is the repository your invite gives. Four things to know:

  • version fetches that release's Linux download. Always set it, and to the same release as the uses: line, without the v that the tag has.
  • app and specs are the defaults, so a repository that keeps them there can leave both out.
  • Specs. Nikasa reads nk/specs when it is there. With no specs, the report covers startup only.
  • The two images must already be built or pulled on the runner.

The tokens #

The token input reads the release, and posts the comment unless comment-token is set. It starts as the job's own github.token, which cannot read another private repository. So it cannot read <nikasa-repo>: give token a secret that can, as above.

That token may not write to your pull request. So the workflows below also set comment-token: ${{ github.token }}, and it alone posts the comment.

The job needs no Docker login for Nikasa's images.

Saving the old build's runs #

To save the old build's runs between jobs, add secret-key: ${{ secrets.NK_SECRET_KEY }}, as the workflows below do. A first run does not need it. Without it, every job makes a new key, so the compare runs in full. See The secret key.

Let nk write the job #

nk init --ci writes the whole job for you:

shell
nk init --ci

Here is what it prints in a repository with no workflow yet:

output
read no workflow: .github/workflows holds no .yml file
wrote: nk/ci/github.yml, the label example with myapp:old and myapp:new as the images
copy: cp nk/ci/github.yml .github/workflows/nk.yml
secret: add NK_SECRET_KEY to the repository's Actions secrets (openssl rand -hex 32 makes one)
tests: found a playwright suite in the root; add it once to nk/app.yaml, under x-nk: tests (driver: playwright), and the job records it; until then it compares with no requests and says so
next: nk init, then nk try: the job reads nk/app.yaml, which does not exist yet, so it cannot run until you commit that file
Line What it says
read What it read. Here the folder holds no .yml file
wrote The file it wrote. Here the label example is the first of the Three workflows to copy, the one that runs when a pull request gets the nk label. The image names come from your app, here myapp. The copies on this page use app:old and app:new
copy The command that puts the file where GitHub reads it
secret The repository secret to add
tests What the job records, or the suite it found and what to add once
next What to do first, when nk/app.yaml does not exist yet

It reads .github/workflows and writes nk/ci/github.yml, never over an earlier one. It prints at most 8 lines. Nothing changes in your repository until you copy the file.

Add two inputs before you copy it #

nk init --ci writes the Action step with its uses: tag, the version of the Nikasa that wrote it, and no version: or token:. Add these under with::

Input Value Why
version 0.3.14, the same release as the tag Without it, the Action builds nk from its own source on the runner instead of fetching that release
token ${{ secrets.NK_RELEASE_TOKEN }}, as in The step Without it, the job's own token cannot read <nikasa-repo>, and the job stops with the error below
comment-token ${{ github.token }} Keeps the comment posting with the job's own token

The error you get without token:

output
nk-ci: could not read release v0.3.14 of <nikasa-repo>: check NK_CI_VERSION and NK_CI_REPOSITORY, and that NK_CI_TOKEN can read it

The secret: line above names NK_SECRET_KEY. NK_RELEASE_TOKEN is the second repository secret to add: see Three workflows to copy.

What it writes #

Situation The file
It finds the job that builds your image One job to add at the end of that workflow. It waits for the build, gets this commit's image, checks the base branch's commit out into .nk-base, gets the base's image, and runs the Action. Each image is pulled by its tag, and built when the pull fails. A tag with no github.sha in it cannot name the base's image, so both sides are built
It finds no such job The first workflow below, with the Dockerfile and folder nk init chose. A build that needs steps before docker build needs them added too
There is no app file yet The job cannot run, as it reads nk/app.yaml. The last line printed then says to run nk init, then nk try, and to commit the file. With a draft already there, that line is left out

Two more parts of the job:

  • The app's config. The Nikasa step gets the env: block of your test job as it is. Then it gets one route for the settings that nk/app.yaml reads with no value, which that block does not set and no env file in git sets. It is never both routes. Either NAME: ${{ secrets.NAME }} for each setting, or, when a service reads an env file that git does not track, a step before the compare that writes the file from one secret, NK_ENV_FILE, and no secret lines. A secret: line says which. See The app's config.
  • Your tests drive the compare. The Action step has record: .nk-base. It records the suite you name under x-nk: tests on the old build, from the base branch's checkout. See Your tests drive the compare. The tests: line says what the job records. Each ${NAME} your env takes from the machine goes on the job's Nikasa step as ${{ secrets.NAME }}, and a secret: line names it.

What you get #

  • A comment on the pull request with report.md, updated on each run.
  • The job summary, with report.md.
  • The nk-report artifact, with report.txt, report.json, report.md and information.jsonl.

Each counted change in the comment has a link that opens a new issue in your repository, filled in from the report. A counted change is one of the changes the report's first line adds up, as Words in a report says.

The output folder never leaves the runner. A pull request from a fork gets a read-only token, so the comment step fails there, and the summary and the artifact still carry the report.

Exit status #

The job passes with the report unless you add --fail-on-change.

Exit status Meaning The job
0 Nikasa compared Passes
1 With --fail-on-change, a change showed in every new run Fails
2 Nikasa could not compare Fails

Exit status has the details.

Make room on the runner #

Below 5 GB free, a compare lets go of what it can and may stop early. Building your image twice can use most of what GitHub's runner has free.

The workflows below start by removing toolchains the job never uses from a GitHub-hosted runner:

  • the Android SDK (/usr/local/lib/android);
  • the Haskell compiler, GHC (/usr/local/.ghcup and /opt/ghc);
  • the .NET SDK (/usr/share/dotnet);
  • CodeQL's tools (/opt/hostedtoolcache/CodeQL).

If you add the step to a job of your own, make room the same way, or build fewer images. First check that no later step needs those toolchains, and leave out any path a later step uses.

Three workflows to copy #

timeout-minutes in the workflows is a ceiling for the whole job, image builds included. Set your own from how long a compare takes.

Before you copy #

Add two repository secrets, in the repository's Actions secrets:

Secret What it holds
NK_RELEASE_TOKEN The token from your invite. The workflows pass it as token
NK_SECRET_KEY A key you make once with openssl rand -hex 32. The secret key section of Saved baselines says what it is for

All three pass secret-key, so each keeps a saved baseline in the Actions cache. Anyone who can open a pull request that runs workflows can read its masked parts. The recorded outside calls inside it are encrypted.

On request, with a label #

Adding the nk label to a pull request compares it with its base branch and posts the report as a comment. The comment is updated on every later push while the label stays. Copy to .github/workflows/nk.yml.

yaml
name: nk

on:
  pull_request:
    types: [labeled, synchronize, reopened]

permissions:
  contents: read
  pull-requests: write

jobs:
  nk:
    if: >-
      contains(github.event.pull_request.labels.*.name, 'nk') &&
      (github.event.action != 'labeled' || github.event.label.name == 'nk')
    runs-on: ubuntu-24.04
    timeout-minutes: 90
    steps:
      - name: Make room on the runner
        if: runner.environment == 'github-hosted'
        run: |
          # Android SDK, GHC (Haskell), .NET SDK and CodeQL: toolchains this job never uses.
          sudo rm -rf /usr/local/lib/android /usr/local/.ghcup /opt/ghc /usr/share/dotnet /opt/hostedtoolcache/CodeQL
          df -h /

      - uses: actions/checkout@v6

      - name: Build the new side
        run: docker build -t app:new .

      # Checked out after the new image is built, as .nk-base sits inside its build context.
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.base.sha }}
          path: .nk-base

      - name: Build the base side
        run: docker build -t app:old .nk-base

      # Settings nk init --ci names go in env: on this step, as NAME: ${{ secrets.NAME }}, only for secrets you set. See The app's config below.
      - uses: <nikasa-repo>@v0.3.14
        with:
          version: 0.3.14
          # The token from your invite, kept as a repository secret.
          token: ${{ secrets.NK_RELEASE_TOKEN }}
          comment-token: ${{ github.token }}
          old: app:old
          new: app:new
          app: nk/app.yaml
          secret-key: ${{ secrets.NK_SECRET_KEY }}
          record: .nk-base

With no x-nk: tests in the app file, record records nothing and the job runs as it would without it.

In a merge queue #

Every change waiting to merge is compared with the branch it merges into, and a change stops it.

To set it up:

  1. Copy the file below to .github/workflows/nk.yml.
  2. Make its nk check required.
  3. Require the merge queue on the branch.
yaml
name: nk

on:
  pull_request:
  merge_group:
    types: [checks_requested]

permissions:
  contents: read

jobs:
  nk:
    if: github.event_name == 'merge_group'
    runs-on: ubuntu-24.04
    timeout-minutes: 60
    steps:
      - name: Make room on the runner
        if: runner.environment == 'github-hosted'
        run: |
          # Android SDK, GHC (Haskell), .NET SDK and CodeQL: toolchains this job never uses.
          sudo rm -rf /usr/local/lib/android /usr/local/.ghcup /opt/ghc /usr/share/dotnet /opt/hostedtoolcache/CodeQL
          df -h /

      - uses: actions/checkout@v6

      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.merge_group.base_sha }}
          path: .nk-base

      - name: Build both sides
        run: |
          docker build -t app:old .nk-base
          docker build -t app:new .

      # Settings nk init --ci names go in env: on this step, as NAME: ${{ secrets.NAME }}, only for secrets you set. See The app's config below.
      - uses: <nikasa-repo>@v0.3.14
        with:
          version: 0.3.14
          # The token from your invite, kept as a repository secret.
          token: ${{ secrets.NK_RELEASE_TOKEN }}
          old: app:old
          new: app:new
          app: nk/app.yaml
          secret-key: ${{ secrets.NK_SECRET_KEY }}
          args: --fail-on-change
          comment: "false"

Every night #

The image you run in production is compared with the default branch as it is now, both in the sandbox. So drift that no single pull request showed is reported before the next release.

The job passes with the report in its summary and artifact. Add args: --fail-on-change to fail it when anything changed.

To set it up, copy the file below to .github/workflows/nk-nightly.yml. Name your production image on the two lines that pull and tag it, docker pull and docker tag, in the step called Production image and the default branch.

yaml
name: nk nightly

on:
  schedule:
    - cron: "17 2 * * *"
  workflow_dispatch:

permissions:
  contents: read
  packages: read

jobs:
  nk:
    runs-on: ubuntu-24.04
    timeout-minutes: 90
    steps:
      - name: Make room on the runner
        if: runner.environment == 'github-hosted'
        run: |
          # Android SDK, GHC (Haskell), .NET SDK and CodeQL: toolchains this job never uses.
          sudo rm -rf /usr/local/lib/android /usr/local/.ghcup /opt/ghc /usr/share/dotnet /opt/hostedtoolcache/CodeQL
          df -h /

      - uses: actions/checkout@v6

      - name: Production image and the default branch
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          echo "$GH_TOKEN" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
          docker pull ghcr.io/${{ github.repository }}:production
          docker tag ghcr.io/${{ github.repository }}:production app:old
          docker build -t app:new .

      # Settings nk init --ci names go in env: on this step, as NAME: ${{ secrets.NAME }}, only for secrets you set. See The app's config below.
      - uses: <nikasa-repo>@v0.3.14
        with:
          version: 0.3.14
          # The token from your invite, kept as a repository secret.
          token: ${{ secrets.NK_RELEASE_TOKEN }}
          old: app:old
          new: app:new
          app: nk/app.yaml
          secret-key: ${{ secrets.NK_SECRET_KEY }}
          jobs: "2"

The app's config #

The Nikasa step gets the env: block of your test job as it is. Then it gets one of two routes for the settings nk/app.yaml reads with no value, which that block does not set. It is never both. nk init --ci writes the route it finds.

One secret line per setting #

Write NAME: ${{ secrets.NAME }} for each setting. nk init --ci prints which secrets to add:

output
secret: add APP_SECRET, SITE_ROOT to the repository's Actions secrets

Add those secrets once, in the repository's settings. The step then carries them, shown here without its other inputs:

yaml
- uses: <nikasa-repo>@v0.3.14
  with:
    version: 0.3.14
    old: app:old
    new: app:new
  env:
    APP_SECRET: ${{ secrets.APP_SECRET }}
    SITE_ROOT: ${{ secrets.SITE_ROOT }}

Only the names nk init listed as to provide go in. A setting that an env file in git sets needs no secret.

The whole file from one secret #

When a service reads, as its env_file:, a file git does not track, a step before the compare writes it. It writes the file at its path from the workspace root, from one secret that holds every setting.

Here the secret NK_ENV_FILE holds the file's text. On GitLab and Jenkins, a variable of that name holds a path instead. The app's config on How CI works says why.

The Nikasa step then gets no secret lines, and nk init --ci prints this:

output
secret: NK_ENV_FILE holds the text of .env for the job, APP_SECRET, SITE_ROOT included

The secret reaches the step through env:, never through ${{ }} inside run::

yaml
- name: Write .env from the NK_ENV_FILE secret
  env:
    NK_ENV_FILE: ${{ secrets.NK_ENV_FILE }}
  run: printf '%s\n' "$NK_ENV_FILE" > .env

The recording that record sets runs from the old build's checkout. It reads this file by the path nk/app.yaml records, from nk/, so it needs nothing more.

Your tests drive the compare #

A compare with no requests sees only each build's startup and idle time. Say once where your tests are, under x-nk: tests in the app file (Give your tests what they need lists the keys). Then name the checkout to run them from:

yaml
- uses: actions/checkout@v6
  with:
    ref: ${{ github.event.pull_request.base.sha }}
    path: .nk-base

- uses: <nikasa-repo>@v0.3.14
  with:
    version: 0.3.14
    token: ${{ secrets.NK_RELEASE_TOKEN }}
    old: app:old
    new: app:new
    secret-key: ${{ secrets.NK_SECRET_KEY }}
    record: .nk-base
  env:
    E2E_PASSWORD: ${{ secrets.E2E_PASSWORD }}   # what x-nk: tests: env takes as ${E2E_PASSWORD}

The job nk init --ci writes has all of this. The job does three things:

  1. Record. After nk setup, nk record runs your tests on the old build. The base branch's tests are the ones to run, as they were written for that build. Tests that fail still leave what they sent.
  2. Compare. The compare sends that recording again to both builds, instead of specs or nk/specs. It makes its old runs, as a new recording matches no saved baseline.
  3. Report. report.md, and so the summary and the comment, opens with how the tests went. A warning from nk record, such as most tests not passing, follows it. The job's log has the test tool's last lines.

The opening looks like this:

output
**Your tests drove this compare.** While they were recorded on the old build: 12 passed, 2 failed. The 61 requests they sent were replayed against both builds.

When nothing is recorded #

The job still passes with a report: see what counts as nothing. The report opens by saying why:

output
**Your tests did not drive this compare.** nk/app.yaml has no `x-nk: tests` to say where they are, so nothing was recorded. It sent no requests, so this report covers each build's startup and idle time.

The recording stays on the runner #

The Action never uploads or caches the recording, and each job records again. An Actions cache can be read by anyone who can open a pull request that runs workflows, and an old image built again gets a new id, so a cache would rarely match anyway. Only the four reports leave the runner.

Time and room #

Give the job 90 minutes. The 30 minutes of record-minutes come on top of the image builds and the compare, and a job that reaches its own limit posts no report.

The driver's image adds about 3.5 GB for Playwright, so keep the job's "Make room on the runner" step.

Inputs #

Input Default Meaning
old, new required The two images, already built or pulled on the runner
app nk/app.yaml The app file, as nk compare --app takes it
specs nk/specs, which may be absent The folder of .hurl files. With no input and no nk/specs, the compare runs with no requests and the log says so. A folder you name must exist, or the job fails
record none The checkout to run your tests from, such as .nk-base. Without it nothing is recorded (above)
record-minutes 30 How long the recording may take before it is stopped, which counts as nothing recorded
record-args none More nk record arguments, split on whitespace, such as --seed-dump dump.sql
format text What the job's log shows; the report files are always written
jobs 1 Runs at once, each on a sandbox network of its own
args none More nk compare arguments, split on whitespace, such as --fail-on-change
version source The Nikasa release to fetch, such as 0.3.14, as the Linux download the runner can run. Set it to the release in your uses: tag. The default, source, builds nk from the Action's own source on the runner instead of fetching a release
comment true Post report.md on the pull request, updating Nikasa's earlier comment
token github.token Reads the Nikasa release, and posts the comment unless comment-token is set. The job's own token cannot read <nikasa-repo>, so give it the release token from your invite
comment-token token Posts the comment, for a job whose token reads the release but may not write to the pull request, such as ${{ github.token }}
secret-key none The secret key, from a repository secret. Needed for a saved baseline
baseline true Keep the old build's runs in the Actions cache; only with secret-key
baseline-expiry 7d The check age: how long a saved baseline is used before a fresh old run checks it
baseline-store the app file's x-nk: baseline_store Keep saved baselines in your own storage instead; needs secret-key
baseline-store-endpoint, baseline-store-region none An S3-compatible store's endpoint, and an s3:// store's region

The Action has two outputs:

Output What it holds
status Nikasa's exit status
reports The folder holding the report files

The Saved baselines page explains the baseline inputs.

Next steps #

Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.