Contrast check in your CI
Why
Facto ships the Valentus theme with several color schemes, and extensions add their own CSS and dynamic UI, such as the search dropdown.
A problem can show up in one scheme or one UI state while everything else looks fine.
contrast-check loads the built site in Chrome once per color scheme the paint declares, opens dynamic UI such as search results, and reports WCAG AA failures as errors and near misses as warnings, each with a suggested color.
Built into Facto (since v0.4.0)
contrast-check (contrast-check-v0.3.1) is a Facto dependency.
The facto-stack extension runs it on the published site after every antora build, so you do not add a CI step.
Full reference: chassis contrast-check docsunchecked and the package READMEunchecked.
What the default run does:
-
Every color scheme the paint declares (light and dark for Valentus).
-
Dynamic states
search-resultsandfixtures: after the static check, each page is reloaded, a query is typed into the search box (antora-search-chat registers the sample state), and the open dropdown is checked. Motion is reduced and transitions are off, so the end state is what gets measured. -
Up to 20 pages (
maxPages: 20). Each page costs about 10-15 s per scheme with both states, so 20 pages is roughly 8 minutes on a GitHub-hosted runner. Raise it for a nightly run, or list key pages withpages. -
Fail scope
dark-and-states: the build fails on WCAG AA errors in dark mode, and on errors a dynamic state introduces (a state re-checks the whole page, so a light-mode issue already on the static page is not counted twice). Every other finding, light-mode static pages and all warnings, is printed as a report and does not fail the build. -
Default suppressions from
lib/contrast-check.suppress.json, each with a reason and an expiry date. -
Chrome: found at the usual Linux, macOS or Windows paths, or set
CONTRAST_CHECK_CHROME. Without a browser the check is skipped with a warning locally, and fails the build whenCIis set.
Per-site override
Set the pack key contrastCheck in the facto-stack extension entry of your playbook:
antora:
extensions:
- require: '@antora-supplemental/facto-stack'
contrastCheck:
failOn: error # error (default) | warning | none
failScope: dark-and-states # default; `all` also fails light-mode static errors
maxPages: 20 # default 20
pages: "index.html,guides/**/*.html"
schemes: "light,dark" # default: every scheme
states: [search-results, fixtures] # add reveal-hidden for a stricter (noisier) pass
config: contrast-check.config.json # default: picked up from the playbook dir
suppress: contrast-check.suppress.yaml
json: build/contrast-check/report.json # default; full report incl. every exempted finding
exempted: summary # exempted findings as info lines: summary (default), all, none
defaultSuppressions: true # false drops Facto's reviewed suppressions
requireBrowser: false # default: true when CI is set
engine: auto # ui-check when the binary is on PATH / UI_CHECK_BIN, else builtin
# uiCheckBin, uiCheckProfiles # optional; UI_CHECK_BIN and UI_CHECK_PROFILES also work
# exceptions: site-waivers.kdl # extra native KDL waivers (repeatable)
# includeAdvisory: true # include ui-check advisory (info) findings
Turn it off with contrastCheck: false (or enabled: false).
Environment overrides: FACTO_CONTRAST_CHECK=0 skips the check, FACTO_CONTRAST_CHECK_FAIL_ON sets failOn and FACTO_CONTRAST_CHECK_FAIL_SCOPE sets failScope.
A practical rollout for a site that wants a stricter gate: keep the default until dark mode is clean, then set failScope: all, and move to failOn: warning only if near misses should fail too.
Policy engine and the four-tier ledger
When @antora-supplemental/contrast-check 0.5.0 or later is installed, Facto can evaluate the collected measurements with the ui-checkunchecked CLI instead of the built-in checker (the GitHub repo is still dev-centr/view-check until that rename is published).
The default is engine: auto: if a ui-check binary is on PATH (or UI_CHECK_BIN / contrastCheck.uiCheckBin is set), Facto uses it; otherwise it keeps the built-in checker, so CI stays green until a published ui-check release is installed. Legacy VIEW_CHECK_BIN / contrastCheck.viewCheckBin and engine: view-check still work.
ui-check uses a four-tier KDL profile ledger. A waiver clears any tier.
| Tier | Label | Facto default |
|---|---|---|
|
|
Fails the build (in |
|
|
Fails the build (in |
|
|
Reported only, unless |
|
|
Reported only when |
Waivers are native KDL --exceptions files. Facto layers:
-
lib/contrast-check.suppress.json— the reviewed default suppressions. contrast-check 0.5.0 bridges them to KDL when the engine isui-check.lib/contrast-check.exceptions.kdlis the same list in native KDL, for sites that want to pass it themselves (setdefaultSuppressions: falsefirst so the same id is not waived twice). -
lib/contrast-check.legacy-light.kdl— whenfailScopeisdark-and-states(the default):waive "*" mode="light" state="default". Light-mode static findings are exempted rather than left as unexempted report-only findings. Dark mode and dynamic states still block. SetfailScope: allto drop this waiver. -
Per-site
contrastCheck.exceptionsand anycontrastCheck.suppressfile whose name ends in.kdl.
Existing JSON/YAML contrast-check.suppress.json files keep working: contrast-check 0.5.0 bridges them to KDL when the engine is ui-check.
link-not-distinct and near-identical-colors are in the quality tier, so they are warnings under the default failOn: error and fail only with failOn: warning / --strict, matching the built-in checker. Token-pair failures are also quality (token-pair-drift).
Running it outside Facto (GitLab CI and others)
The CLI needs Node.js 20 or later and Chrome or Chromium.
It finds /usr/bin/google-chrome, /usr/bin/chromium or Chrome on Windows; otherwise set CONTRAST_CHECK_CHROME to the browser path.
Install from the git tag
The package installs straight from the chassis git tag; it does not need the npm registry entry.
Add it to your site’s devDependencies:
"devDependencies": {
"@antora-supplemental/contrast-check": "github:antora-supplemental/antora-ui-chassis#contrast-check-v0.3.1&path:packages/contrast-check"
}
Or check out the tag and run the CLI from the checkout, the way the GitHub Action does:
git clone --depth 1 --branch contrast-check-v0.3.1 https://github.com/antora-supplemental/antora-ui-chassis.git .contrast-check
(cd .contrast-check/packages/contrast-check && npm install --no-save --omit=dev --ignore-scripts)
node .contrast-check/packages/contrast-check/bin/contrast-check.js build/site --fail-on none
GitLab CI example
contrast-check:
stage: test
image: node:20
before_script:
- apt-get update && apt-get install -y chromium
script:
- npm install
- npx antora antora-playbook.yml
- npx contrast-check build/site --pages "index.html,**/*.html" --max-pages 50 --fail-on none --json=contrast-check.json
artifacts:
when: always
paths: [contrast-check.json]
Common flags: --pages <list>, --max-pages <n>, --schemes <ids> (default every scheme), --paint <file.css>, --config <file>, --suppress <file>, --exempted summary|all|none, --show-suppressed, --fail-on-stale, --json=<file>, --quiet.
Exit codes: 0 clean (under --fail-on), 1 failed, 2 usage or setup error.
Roll out with --fail-on
|
Report only; never fails. Start here to see the findings. |
|
Fails on any finding (same as |
|
Fails on WCAG AA errors only. The default; the usual end state. |
A practical order: none while you fix or suppress the first report, then error to gate merges.
Move to warning only if you also want near misses to fail.
The config key failOn sets the same thing.
Exempted findings in the log
Suppressed findings are not hidden. The check prints an info block on stdout (so it shows even with Antora --log-level warn): one line per suppression entry with its expiry, reason and error/warning counts, then up to three example lines such as
info exempted by devcentr-accent-links-light until 2027-01-31: 412 finding(s) (412 error, 0 warning): brand accent ...
exempted: color-contrast light/light a #178f80 on #f3f5f8 until 2027-01-31 (devcentr-accent-links-light: ...)
In GitHub Actions each entry is also a ::notice and the step summary has an exempted table. Facto’s closing line separates what is left:
contrast-check: 89 finding(s) reported only (outside fail scope dark-and-states / level error): 32 unexempted error(s), 57 unexempted warning(s); 0 exempted by suppressions; report build/contrast-check/report.json
The full JSON report (every finding and every exempted finding with suppressedBy, suppressReason and suppressExpires) is kept at build/contrast-check/report.json; upload it as a CI artifact.
Config and suppressions (standalone CLI)
Put contrast-check.config.json in the directory the check runs from (it is picked up by default), or pass --config / the config input.
Unknown keys are an error.
A suppress entry accepts a known finding: reason is required, and after expires (YYYY-MM-DD) the entry is ignored and reported as suppression-expired.
{
"pages": ["index.html", "**/*.html"],
"maxPages": 50,
"failOn": "error",
"failOnStale": false,
"suppress": [
{
"rule": "color-contrast",
"selector": ".search-input::placeholder",
"scheme": ["dark"],
"reason": "Placeholder text, not content; tracked in #42",
"expires": "2027-03-31"
}
]
}
An entry that matches nothing is reported as suppression-stale; add --fail-on-stale (failOnStale: true) to fail on stale or expired entries.
Prefer suppress over ignore, which drops findings silently.
Inline opt-out
Mark an element (or an ancestor) in your templates or content:
<nav class="api-nav" data-contrast-check-ignore="focus-not-visible hover-no-change">
The value lists rule ids, aliases or globs; an empty value suppresses every rule.
These show as suppressed by inline.
Paint and token findings have no element and need a suppress entry.
== Source-aware page selection (Facto 0.5.1)
Keep a successful-run baseline per content source, then select every changed/new page plus one representative per discovered layout and your configured extension representatives. The selection is sorted identically on Windows and Linux. A changed include selects only its transitive page dependents. Navigation, component descriptors, images, theme/UI and preprocessor changes use the representative set, not every page. New pages remain mandatory even when old Git history is no longer available.
contrastCheck:
maxPages: 20
maxDurationMs: 600000 # total audit budget, not per page
pages: [home/index.html, home/glossary/index.html]
sampling:
baseline: build/contrast-check-baseline.json
# baseRef: origin/main # optional explicit comparison base
Restore the baseline from the last successful CI/deploy and save it only when the whole workflow succeeds. The checker writes a candidate baseline after contrast passes; CI must not cache it from a failed deployment. A missing/unresolvable source base uses the sorted broad fallback budget plus layout/configured representatives; known changes and new pages are never capped. Without a saved baseline, sampling.baseRef or FACTO_CONTRAST_BASE_REF can provide the Git base. To reproduce CI locally, use the same baseline and source revisions. Set sampling: false only to explicitly opt out and restore the legacy page-cap behavior.
Budget and carry-over
Facto 0.5.3 audits pages in priority order: layout and configured representatives, one representative per page group, carried-over pages, then changed pages, most recently changed first. contrastCheck.budgetMs (default 85% of maxDurationMs) is a soft budget. The audit stops before a page that would not finish in time. If every audited page passes, the build passes, and the unchecked pages are saved with the baseline as pending. The next run checks them right after the representatives. A large edit therefore takes several green runs to audit fully, instead of failing every run and growing the backlog.
Representatives keep the full audit, with focus, hover and dynamic states. Changed and carried-over pages get axe and the text probe in every scheme (sampling.contentOnly: false audits them fully). sampling.groups (default ['/changelog-details/']) audits one changed page per group of same-template prose pages. A source added since the last green run needs no broad fallback. An unresolvable base falls back to that source’s pages only.
Source-only changes and total audit budget
Facto 0.5.1 no longer expands navigation, images, theme, UI or preprocessor edits into every page in a source. Changed pages are the source pages whose own content changed, plus transitive include dependents (partials, examples or included pages). Escaped include examples do not count; conditional references are conservatively tracked. Capturing the original catalog before conversion keeps rendered navigation out of the diff.
contrastCheck.pages defines fixed extension representatives; one page per discovered layout is also selected. Every selected path logs its reason. The JSON report preserves those reasons in meta.selection.reasons. Unknown bases still use the broad fallback, and new source pages are always included.
contrastCheck.maxDurationMs defaults to 600000 (ten minutes total, across all pages, schemes and states). The underlying CLI accepts --max-duration-ms; its config key is maxDurationMs. Since 0.5.3 the soft budgetMs stops first and carries pages over. Hitting the hard limit before the first page finishes is a failed, incomplete audit, even with failOn: none; the successful baseline is not advanced. Browser cleanup allows up to five additional seconds. For a deliberate bulk edit, increase the budget explicitly instead of silently truncating changed pages.