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:
- It gets Nikasa and checks it against the release's
SHA256SUMS. - It runs
nk setup. - It records your tests, if you ask it to.
- It works out the saved baseline's key.
- It compares.
- 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.
-
Download the script and its files from the release, and check them:
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) -
Run the compare. Upload
nk-ci/nk-reportsto the CI's artifacts, nevernk-ci/nk-run: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/ |
For your CI's artifact step |
| A note when a baseline was not saved | nk-ci/, 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. |
See below |
| A comment | Nowhere | The script posts nothing. report. 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 |
Ticket links #
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:
- The
recordstep runsnk recordfrom that folder, on the old build. - The compare sends the recording again.
report.mdandreport.txtopen 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:
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:
NK_CI_ARGS="--env-file $NK_ENV_FILE" NK_CI_RECORD_ARGS="--env-file $NK_ENV_FILE" bash nk-ci-script/nk-ci.shSteps #
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:
- Run
nk-ci.sh install setup record key. - If
nk-ci/nk-baseline.keyis there, restorenk-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" }}. - Run
nk-ci.sh compare save reports. - If
nk-ci/nk-baseline/saved.txtsayssaved=true, savenk-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/, which may be absent |
The folder of . 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 |
./ |
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/ |
The Nikasa the steps run |
nk-secret. |
NK_CI_SECRET_KEY, readable by the job's user only |
nk-baseline. |
The saved baseline's key, one line. There only when a saved baseline is used |
nk-baseline. |
The baseline store's URL, one line. There only with a key and a store |
nk-baseline/ |
The saved baseline. saved. in it says saved=true when it needs saving |
nk-bin/ |
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. |
What nk record said |
nk-tests. |
What the reports open with, when NK_CI_RECORD is set |
nk-run/ |
The compare's output folder: never upload it |
nk-reports/ |
report., report., report. and information.: 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 #
- How CI works: what every CI shares, and the runner you need.
- Saved baselines: what the secret key is for, and how a baseline speeds up compares.
- Baseline storage: keep baselines in your own bucket.
- Tickets from a report: open an issue from a change.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.