ci(docs): scan only the guides production serves in the daily accessibility scan

The scan reads its page list from master, so a guide merged since the last
production deploy returned 404 and failed it. When DOCS_E2E_SITEMAP_URL is
set, e2e:docs:all keeps only the guides that are also in that sitemap, and
lists the rest as not on production yet. The run fails when the sitemap
can't be read, lists no guides, or is missing more than a tenth of them.
This commit is contained in:
alexisintech committed 2026-12-02 17:01:20 -07:00
1 parent 1ba714978e
commit 490fa2f2e1
5 files changed
+131 -5

No files matched your search

+4 -1
View File
@@ -1,5 +1,7 @@
# Scans every docs guide on production for accessibility violations, daily.
# docs-master-alert.yml posts failures to Slack.
# The page list is the guides in apps/docs/content/guides on master that also appear in
# https://supabase.com/docs/sitemap.xml, so a guide merged since the last production deploy waits
# for the next scan. docs-master-alert.yml posts failures to Slack.
name: Docs Accessibility Scan
@@ -58,6 +60,7 @@ jobs:
run: pnpm run e2e:docs:all --grep @a11y
env:
PLAYWRIGHT_BASE_URL: https://supabase.com
DOCS_E2E_SITEMAP_URL: https://supabase.com/docs/sitemap.xml
- name: Upload Playwright report
if: failure()
+17 -3
View File
@@ -127,6 +127,18 @@ Run this against a deployed site, not the local dev server — see
[Local docs server](#local-docs-server) for why local runs are unreliable for
pages linking into reference docs or server-side auth guides.
To test only the guides a deployed site serves, set `DOCS_E2E_SITEMAP_URL` to
its sitemap. Guides missing from the sitemap, such as ones merged since the last
deploy, are skipped and listed in the output:
```bash
PLAYWRIGHT_BASE_URL=https://supabase.com \
DOCS_E2E_SITEMAP_URL=https://supabase.com/docs/sitemap.xml pnpm e2e:docs:all
```
The run fails instead when the sitemap can't be read, or when more than a tenth
of the guides are missing from it.
## What the suite covers
### In scope
@@ -174,9 +186,11 @@ The `@a11y`-tagged test scans each in-scope page with `@axe-core/playwright`. It
reports WCAG 2.1 A/AA violations in the main article, and fails on the rules in
`ENFORCED_RULES` in `utils/axe-helpers.ts`, which it checks across the whole page.
The scans are slow, so Docs E2E runs skip them. Instead, the Docs Accessibility
Scan workflow (`.github/workflows/docs-a11y-scan.yml`) scans every MDX guide on
production daily at 05:17 UTC, and a failure posts to the docs alerts channel in
Slack. To start it by hand, run `gh workflow run docs-a11y-scan.yml`.
Scan workflow (`.github/workflows/docs-a11y-scan.yml`) scans every MDX guide
that production serves daily at 05:17 UTC, and a failure posts to the docs alerts channel in
Slack. A guide merged since the last production deploy is scanned once it's
deployed, as described in [Run every in-scope page](#run-every-in-scope-page). To
start it by hand, run `gh workflow run docs-a11y-scan.yml`.
```bash
PLAYWRIGHT_BASE_URL=https://supabase.com pnpm e2e:docs:a11y
+6 -1
View File
@@ -3,6 +3,7 @@ import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { runSuite } from '../../shared/run-suite.ts'
import { onlyProductionPages } from '../utils/production-pages.ts'
import { resolveAllDocsPages, resolveDocsScope } from '../utils/resolve-docs-scope.ts'
runSuite({
@@ -13,7 +14,11 @@ runSuite({
baseRefEnv: 'DOCS_E2E_BASE_REF',
defaultBaseUrl: 'http://localhost:3001',
resolveScope: resolveDocsScope,
resolveAllPages: resolveAllDocsPages,
resolveAllPages: async (repoRoot) => {
const pages = await resolveAllDocsPages(repoRoot)
const sitemapUrl = process.env.DOCS_E2E_SITEMAP_URL
return sitemapUrl ? onlyProductionPages(pages, sitemapUrl) : pages
},
}).catch((error) => {
console.error(error instanceof Error ? error.message : error)
process.exit(1)
+51
View File
@@ -0,0 +1,51 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { sitemapGuidePaths, splitByProduction } from './production-pages.ts'
test('reads guide paths from the sitemap, including tags the formatter wrapped', () => {
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://supabase.com/docs/guides/ai</loc>
</url>
<url>
<loc
>https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration/oauth-scopes</loc
>
</url>
<url>
<loc>https://supabase.com/docs/guides/auth/</loc>
</url>
<url>
<loc>https://supabase.com/docs/reference/javascript/select</loc>
</url>
<url>
<loc>not a url</loc>
</url>
</urlset>`
assert.deepEqual(
[...sitemapGuidePaths(xml)],
[
'/docs/guides/ai',
'/docs/guides/integrations/build-a-supabase-oauth-integration/oauth-scopes',
'/docs/guides/auth',
]
)
})
test('skips a page that is on master but not yet on production', () => {
const pages = Array.from({ length: 20 }, (_, index) => `/docs/guides/page-${index}`)
const production = new Set(pages.slice(1))
assert.deepEqual(splitByProduction(pages, production), {
live: pages.slice(1),
notOnProduction: ['/docs/guides/page-0'],
})
})
test('fails when too many pages are missing for the sitemap to be complete', () => {
const pages = Array.from({ length: 20 }, (_, index) => `/docs/guides/page-${index}`)
const production = new Set(pages.slice(3))
assert.throws(() => splitByProduction(pages, production), /3 of 20 guides are missing/)
})
+53
View File
@@ -0,0 +1,53 @@
// The sitemap's formatter can wrap a long tag as `<loc\n >url</loc\n>`
const LOC_RE = /<loc\s*>\s*([^<]+?)\s*<\/loc\s*>/g
const DOCS_GUIDES_PREFIX = '/docs/guides/'
const SITEMAP_TIMEOUT_MS = 30_000
// More pages than this missing from production points to a broken sitemap, not a deploy lag
export const MAX_NOT_ON_PRODUCTION_SHARE = 0.1
export function sitemapGuidePaths(xml: string): Set<string> {
const paths = new Set<string>()
for (const match of xml.matchAll(LOC_RE)) {
let pathname: string
try {
pathname = new URL(match[1]).pathname
} catch {
continue
}
if (pathname.startsWith(DOCS_GUIDES_PREFIX)) paths.add(pathname.replace(/\/+$/, ''))
}
return paths
}
export type ProductionSplit = { live: string[]; notOnProduction: string[] }
export function splitByProduction(pages: string[], production: Set<string>): ProductionSplit {
const live = pages.filter((page) => production.has(page))
const notOnProduction = pages.filter((page) => !production.has(page))
if (notOnProduction.length > pages.length * MAX_NOT_ON_PRODUCTION_SHARE) {
throw new Error(
`${notOnProduction.length} of ${pages.length} guides are missing from the production ` +
`sitemap, more than a deploy lag explains. Check that the sitemap is complete.`
)
}
return { live, notOnProduction }
}
// Keeps the pages production serves, so a guide merged since the last deploy isn't scanned yet
export async function onlyProductionPages(pages: string[], sitemapUrl: string): Promise<string[]> {
const response = await fetch(sitemapUrl, {
signal: AbortSignal.timeout(SITEMAP_TIMEOUT_MS),
}).catch((error: unknown) => {
throw new Error(
`Couldn't read ${sitemapUrl}: ${error instanceof Error ? error.message : error}`
)
})
if (!response.ok) throw new Error(`${sitemapUrl} returned ${response.status}.`)
const production = sitemapGuidePaths(await response.text())
if (production.size === 0) throw new Error(`${sitemapUrl} lists no docs guides.`)
const { live, notOnProduction } = splitByProduction(pages, production)
for (const page of notOnProduction) console.error(`Skipping ${page}: not on production yet.`)
return live
}