Running accessibility checks on pull request preview deployments
A preview deployment is the closest thing to production a pull request has, and the best place to catch an accessibility regression: before merge, on the real build, with the diff still open in another tab.
Why scan the preview rather than staging
A staging environment shows what has already been merged. By the time a regression shows up there, the pull request that caused it is closed, its author has moved on, and the fix is a new ticket. A preview deployment shows the change itself. If the check runs against it and reports on the pull request, the person who introduced the problem sees it while the code is still in their head.
The workflow
The GitHub Action takes whatever URL your deploy step produced. The shape is: deploy, read the preview URL from that step's output, scan it.
# .github/workflows/a11y.yml
name: Accessibility
on: pull_request
jobs:
a11y:
runs-on: ubuntu-latest
permissions:
pull-requests: write # for the report comment
steps:
- uses: actions/checkout@v4
- id: deploy
run: ./deploy-preview.sh # sets outputs.preview-url
- uses: skiplink/action@v1
with:
urls: |
${{ steps.deploy.outputs.preview-url }}/
${{ steps.deploy.outputs.preview-url }}/pricing
${{ steps.deploy.outputs.preview-url }}/signup
baseline: .skiplink/baseline.json
token: ${{ secrets.SKIPLINK_TOKEN }}
deploy-preview.sh stands in for whatever your host provides. What matters is that the
step writes the URL to $GITHUB_OUTPUT, so the next step can read it.
On the pull request you get a check that goes red only when something new appeared, one comment listing the new violations with rule, impact, page and selector (edited in place on each push rather than posted again), annotations on the run, and a job summary with the same report.
Why the hostname does not matter
Every preview lives at a different address: pr-482.preview.example.com today,
pr-483.preview.example.com tomorrow. A baseline keyed on the full URL would match nothing
on exactly the runs it exists for. Skiplink's baseline entries key on the URL path, so
/pricing on one preview matches /pricing on the next, and on staging, and on
production. You can record the baseline once against any of them:
npx @skiplink/cli scan https://staging.example.com/ https://staging.example.com/pricing \
https://staging.example.com/signup \
--baseline .skiplink/baseline.json --update-baseline
Read the file before you commit it. Every entry is a violation the gate will ignore.
The things that go wrong
The preview is not ready. Some hosts report a URL before the build behind it is serving. If the scan lands on a holding page or a 404, it checks the wrong document. Every result carries the page's HTTP status, and the CLI warns before printing anything else. Above all, never record a baseline from a run that scanned an error page, or the baseline describes the error page and the real one goes unmeasured.
The app renders late. A single-page app that fetches its content after load can be
scanned while it is still a spinner. The wait-for input takes a CSS selector to wait for:
- uses: skiplink/action@v1
with:
urls: ${{ steps.deploy.outputs.preview-url }}/app
wait-for: "[data-testid=dashboard]"
baseline: .skiplink/baseline.json
token: ${{ secrets.SKIPLINK_TOKEN }}
The preview is protected. Many hosts put previews behind a password or a sign-in. The hosted scanner fetches pages from the public internet and cannot get past that; the Action has no input for credentials. The API's scan endpoint does accept custom headers and basic auth (see Scan a URL), and pages behind a real sign-in are better checked from your own tests with the Playwright adapter, which shares the same baseline file.
Pull requests from forks. GitHub does not give repository secrets to workflows run for
pull requests from forks, so SKIPLINK_TOKEN is empty there. For a public repository,
either skip the job on forks or accept that those runs cannot scan:
if: github.event.pull_request.head.repo.full_name == github.repository
A scan that could not run is reported as "could not complete", never as a pass, and the CLI uses a separate exit code for it, so you can tell it apart from a real failure.
Settling in
A new gate is easier to accept if it reports before it blocks. For the first week or two, run it without failing:
- uses: skiplink/action@v1
continue-on-error: true
with:
fail-on: never
urls: ${{ steps.deploy.outputs.preview-url }}
token: ${{ secrets.SKIPLINK_TOKEN }}
The report still appears; nothing goes red. When the team has seen a few reports and the
baseline is committed, remove those two lines. Pin cli-version once you rely on the
gate, so the scanner only changes when you decide it should.
The Action also exposes outputs (passed, new-violations, and report, the path to the
markdown report), which a later step can use, for example to post the count somewhere else.
The full list is in Inputs and
Outputs.
Scans per pull request
Each URL scanned is one scan. Three pages on every push of every pull request adds up: ten pushes across five open pull requests is 150 scans. Pick the pages a change is most likely to affect, typically templates rather than individual articles, and see what counts as a scan when sizing a plan.
What a green check means
No automatically detectable violations were found on the pages you listed, in the state they loaded in. It does not cover keyboard behaviour, focus order or whether the content makes sense, and it does not cover pages you did not list. The list of criteria no scanner detects is where a reviewer's attention should go next.
Related
- Adding accessibility checks to a site that already has violations
- Accessibility Testing GitHub Action
- Accessibility checks in Playwright tests, including pages behind a login
Try it on your own site: scan a URL for free, or read the docs to add a baseline to your pipeline.