Nikasa, home Request an invite
DocsAny other CI

Any other CI

CircleCI, Bitbucket Pipelines, Buildkite or your own. One script, nk-ci.sh, does on any Linux runner with Docker, bash and curl what the GitHub Action does.

On this page

This page is for CircleCI, Bitbucket Pipelines, Buildkite and any CI of your own. One script, nk-ci.sh, runs Nikasa on any Linux runner. It is the same script the GitHub Action and the Jenkins library run.

The script does these things:

  1. It gets Nikasa and checks it against the release's SHA256SUMS.
  2. It runs nk setup.
  3. It records your tests, if you ask it to.
  4. It works out the saved baseline's key.
  5. It compares.
  6. It puts the four reports in one folder.

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

What you need #

  • A Linux runner with Docker, bash and curl.
  • unzip, for a baseline store.
  • The GitHub CLI, gh, for the first step below. Without it, see the note under Run it.
  • The release token, kept as a CI secret.

Your job's own artifact and cache steps do the rest.

Run it #

The script, and the file it sources to pick a download, linux-asset.sh, are in each release beside SHA256SUMS.

  1. Download the script and its files from the release, and check them:

    shell
    v=0.3.14
    GH_TOKEN="$NK_RELEASE_TOKEN" gh release download "v$v" --repo <nikasa-repo> \
      --dir nk-ci-script --pattern nk-ci.sh --pattern linux-asset.sh --pattern SHA256SUMS
    (cd nk-ci-script && sha256sum -c --ignore-missing SHA256SUMS)
  2. Run the compare. Upload nk-ci/nk-reports to the CI's artifacts, never nk-ci/nk-run:

    shell
    status=0
    NK_CI_VERSION=$v NK_CI_REPOSITORY=<nikasa-repo> NK_CI_TOKEN="$NK_RELEASE_TOKEN" NK_CI_SECRET_KEY="$NK_SECRET_KEY" \
      NK_CI_OLD=app:old NK_CI_NEW=app:new NK_CI_APP=nk/app.yaml \
      bash nk-ci-script/nk-ci.sh || status=$?
    exit "$status"

NK_RELEASE_TOKEN is the release token. NK_CI_SECRET_KEY is for saved baselines. To start without a saved baseline, leave it out.

What you get #

What Where Notes
The job's exit status The job It is nk compare's, as in Exit status. The table below lists the values
The reports nk-ci/nk-reports For your CI's artifact step
A note when a baseline was not saved nk-ci/nk-note, and the script's last line The job keeps its status. The last line is nk-ci: the baseline was not saved; the warning above says why. The note is for your CI's own headline
Ticket links report.md See below
A comment Nowhere The script posts nothing. report.md is written to be posted, so a comment step of your own can send it

The exit status:

Status Meaning
0 Nikasa compared
1 With --fail-on-change, a change showed in every new run
2 Nikasa could not compare, or a step before the compare failed, such as a download that does not match SHA256SUMS. The log's nk-ci: line says why

These CIs give Nikasa only the checkout's address. On CircleCI, Bitbucket Pipelines and Buildkite, the link beside each change in report.md opens an issue in the repository the job checked out only when that is on github.com or gitlab.com. Elsewhere, name your tracker. See Tickets from a report.

Your tests drive the compare #

Your tests can supply the requests. Set NK_CI_RECORD to a checkout to run your tests from, such as a checkout of the base branch. Put your tests under x-nk: tests in the app file: Give your tests what they need lists the keys.

Then:

  1. The record step runs nk record from that folder, on the old build.
  2. The compare sends the recording again.
  3. report.md and report.txt open by saying how the tests went.

Secrets your tests read come from the job's environment. Your tests drive the compare says what counts as nothing recorded, the time limit, and what stays on the runner.

The app's config #

Nikasa reads the env file that nk/app.yaml records as x-nk: env_file, then the job's environment, which wins, as in Compose. The recorded path is from nk/, as Compose reads a service's env_file:.

One setting at a time #

Give each setting that nk init lists as to provide to the job as a variable of its own name. Either export it before nk-ci.sh runs, or use your CI's secret variable of that name:

shell
export APP_SECRET=...

A whole file #

To give a file instead, which your CI writes or hands the job as a path, name it in the words nk-ci.sh adds to the compare and to the recording. The file is used in place of the recorded file. Here NK_ENV_FILE holds a path, not the file's text as the secret of that name does on GitHub:

shell
NK_CI_ARGS="--env-file $NK_ENV_FILE" NK_CI_RECORD_ARGS="--env-file $NK_ENV_FILE" bash nk-ci-script/nk-ci.sh

Steps #

nk-ci.sh [step...] runs the steps you name, in the order given. With none named, it runs all of them.

Step What it does
install Gets Nikasa and checks it
setup Runs nk setup
record Records your tests. Does nothing without NK_CI_RECORD
key Works out the saved baseline's key
restore Moves the saved baseline in from a baseline store. Does nothing without a store
compare Compares
save Moves the saved baseline out to the store. Does nothing without a store
reports Puts the reports together

Separate calls share the files under NK_CI_WORK, so a CI's cache step can sit between key and compare. Give NK_CI_RECORD to record, key, compare and reports alike.

A saved baseline in your CI's cache #

Split the run in two around the cache:

  1. Run nk-ci.sh install setup record key.
  2. If nk-ci/nk-baseline.key is there, restore nk-ci/nk-baseline/ from a cache keyed on that file's contents. On CircleCI, for example, the key is {{ checksum "nk-ci/nk-baseline.key" }}.
  3. Run nk-ci.sh compare save reports.
  4. If nk-ci/nk-baseline/saved.txt says saved=true, save nk-ci/nk-baseline/ under that key.

Variables #

Variable Default Meaning
NK_CI_OLD, NK_CI_NEW required The two images, already built or pulled on the runner
NK_CI_APP required The app file, as nk compare --app takes it
NK_CI_SPECS nk/specs, which may be absent The folder of .hurl files that drive the app
NK_CI_RECORD none The checkout to run your tests from, such as a checkout of the base branch
NK_CI_RECORD_MINUTES 30 How long the recording may take
NK_CI_RECORD_ARGS none More nk record arguments, split on whitespace
NK_CI_FORMAT text What the job's log shows
NK_CI_JOBS 1 Runs at once
NK_CI_ARGS none More nk compare arguments, split on whitespace
NK_CI_VERSION none The release to download from GitHub, such as 0.3.14, without the v of the tag
NK_CI_REPOSITORY none Required in practice: the GitHub repository that release is in, <nikasa-repo> from your invite
NK_CI_TOKEN none A GitHub token that can read the release, from a masked CI secret
NK_CI_RELEASE_DIR none A folder holding a release's files, used instead of a download: for a runner with no internet access
NK_CI_NK none An nk already on the runner, used as it is, unchecked
NK_CI_SECRET_KEY none The secret key, from a CI secret. Needed for a saved baseline
NK_CI_BASELINE true Work out the saved baseline's key; only with NK_CI_SECRET_KEY
NK_CI_BASELINE_EXPIRY 7d The check age: how long a saved baseline is used before a fresh old run checks it
NK_CI_BASELINE_STORE the app file's x-nk: baseline_store Keep the saved baseline there: s3://, gs://, az:// or file:///
NK_CI_BASELINE_STORE_ENDPOINT none An S3-compatible store's endpoint
NK_CI_BASELINE_STORE_REGION none An s3:// store's region
NK_CI_BASELINE_STORE_ENCRYPT true Encrypt each saved baseline before upload
NK_CI_RCLONE none An rclone already on the runner, used as it is, unchecked
NK_CI_RUN_ID random Names each saved object
NK_CI_WORK ./nk-ci The folder it keeps everything in

Set one of NK_CI_NK, NK_CI_RELEASE_DIR or NK_CI_VERSION. The first one set is used.

Request files #

With NK_CI_SPECS unset or empty, the compare uses nk/specs when that folder is there. When it is not, the script says so in one line and passes no --specs. Then nk compare reads nk/packs/main if there is one, and otherwise runs with no requests.

Files #

These files are always at these places under NK_CI_WORK:

Path What it is
nk-bin/nk The Nikasa the steps run
nk-secret.key NK_CI_SECRET_KEY, readable by the job's user only
nk-baseline.key The saved baseline's key, one line. There only when a saved baseline is used
nk-baseline.store The baseline store's URL, one line. There only with a key and a store
nk-baseline/ The saved baseline. saved.txt in it says saved=true when it needs saving
nk-bin/rclone The rclone that restore and save run, downloaded and checked on first use
nk-pack/ Your tests as recorded, which makes it a pack (Words in a report). It holds what they sent, passwords too: never hand it on
nk-record.log What nk record said
nk-tests.md What the reports open with, when NK_CI_RECORD is set
nk-run/ The compare's output folder: never upload it
nk-reports/ report.txt, report.json, report.md and information.jsonl: upload these
nk-status nk compare's exit status
nk-note What the job's headline should add, such as that the baseline was not saved. The reports step prints it last

Next steps #

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