diff --git a/.github/workflows/docs-a11y-scan.yml b/.github/workflows/docs-a11y-scan.yml new file mode 100644 index 00000000000..8512df32c62 --- /dev/null +++ b/.github/workflows/docs-a11y-scan.yml @@ -0,0 +1,70 @@ +# Scans every docs guide on production for accessibility violations, daily. +# docs-master-alert.yml posts failures to Slack. + +name: Docs Accessibility Scan + +on: + workflow_dispatch: + schedule: + - cron: '17 5 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +env: + CI: true + +jobs: + a11y: + name: Docs accessibility scan + timeout-minutes: 45 + runs-on: blacksmith-4vcpu-ubuntu-2404 + + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + sparse-checkout: | + e2e/docs + e2e/shared + patches + apps/docs/content/guides + apps/docs/scripts/federated-content/sources + apps/docs/lib/redirects + + - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 + name: Install pnpm + with: + run_install: false + + - name: Use Node.js + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version-file: '.nvmrc' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile --filter=e2e-docs... + + - name: Install Playwright Chromium + run: pnpm -C e2e/docs exec playwright install chromium --with-deps --only-shell + + - name: Run accessibility scan + working-directory: e2e/docs + run: pnpm run e2e:docs:all --grep @a11y + env: + PLAYWRIGHT_BASE_URL: https://supabase.com + + - name: Upload Playwright report + if: failure() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: docs-a11y-playwright-report + path: | + e2e/docs/playwright-report/ + e2e/docs/test-results/ + retention-days: 7 diff --git a/.github/workflows/docs-e2e.yml b/.github/workflows/docs-e2e.yml index 4bf03142218..b4e97a9acec 100644 --- a/.github/workflows/docs-e2e.yml +++ b/.github/workflows/docs-e2e.yml @@ -79,6 +79,7 @@ jobs: apps/docs/content/guides apps/docs/content/_partials apps/docs/scripts/federated-content/sources + apps/docs/lib/redirects - name: Use Node.js if: github.event_name == 'workflow_dispatch' || steps.changes.outputs.docs == 'true' @@ -240,7 +241,7 @@ jobs: - name: Run docs E2E if: steps.base-url.outputs.should_test == 'true' working-directory: e2e/docs - # Accessibility scans are slow, so CI runs skip them. + # Accessibility scans are slow, so they run daily in docs-a11y-scan.yml instead. run: pnpm run e2e:docs --grep-invert @a11y env: PLAYWRIGHT_BASE_URL: ${{ steps.base-url.outputs.url }} diff --git a/.github/workflows/docs-master-alert.yml b/.github/workflows/docs-master-alert.yml index 85ce679490c..6ba6c32926d 100644 --- a/.github/workflows/docs-master-alert.yml +++ b/.github/workflows/docs-master-alert.yml @@ -11,6 +11,7 @@ on: - 'Docs removed anchors' - 'docs_sync' - 'Docs Production Smoke Tests' + - 'Docs Accessibility Scan' - 'Ingest Docs Content for Search V2' - 'Docs Tests' branches: [master] @@ -31,37 +32,28 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DOCS_WEBHOOK_URL }} WORKFLOW_NAME: ${{ github.event.workflow_run.name }} WORKFLOW_URL: ${{ github.event.workflow_run.html_url }} - COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} - COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }} - COMMIT_AUTHOR: ${{ github.event.workflow_run.head_commit.author.name }} - REPO_URL: https://github.com/${{ github.repository }} + TRIGGER: ${{ github.event.workflow_run.event }} run: | - SHORT_SHA="${COMMIT_SHA:0:7}" - FIRST_LINE=$(echo "$COMMIT_MESSAGE" | head -1) - PAYLOAD=$(jq -n \ --arg workflow_name "$WORKFLOW_NAME" \ --arg workflow_url "$WORKFLOW_URL" \ - --arg commit_sha "$COMMIT_SHA" \ - --arg short_sha "$SHORT_SHA" \ - --arg commit_msg "$FIRST_LINE" \ - --arg author "$COMMIT_AUTHOR" \ - --arg repo_url "$REPO_URL" \ - '{ - text: ":rotating_light: \($workflow_name) failed on master", + --arg trigger "$TRIGGER" \ + '(if $trigger == "push" then "push to master" elif $trigger == "schedule" then "scheduled run" elif $trigger == "workflow_dispatch" then "manual run" else "\($trigger) run" end) as $run + | { + text: ":rotating_light: \($workflow_name) failed on a \($run)", blocks: [ { type: "header", text: { type: "plain_text", - text: ":rotating_light: master is broken" + text: ":rotating_light: \($workflow_name) failed" } }, { type: "section", text: { type: "mrkdwn", - text: "*Workflow:* <\($workflow_url)|\($workflow_name)>\n*Commit:* <\($repo_url)/commit/\($commit_sha)|\($short_sha)> \($commit_msg)\n*Author:* \($author)" + text: "*Workflow:* <\($workflow_url)|\($workflow_name)> (\($run))" } } ] diff --git a/e2e/docs/README.md b/e2e/docs/README.md index d4fc508b6b5..e1507a6c9c0 100644 --- a/e2e/docs/README.md +++ b/e2e/docs/README.md @@ -144,6 +144,11 @@ pages linking into reference docs or server-side auth guides. - Non-docs routes such as `/dashboard` and `/ui`, which the link checker skips - Guides that the nav disables, listed in `NAV_DISABLED_PAGES` in `utils/resolve-docs-scope.ts`, because their HTML page returns 404 +- Guides that `apps/docs/lib/redirects/static-redirects.json` redirects + elsewhere, because they have no docs article to test +- Guides with no MDX file, such as the CLI and self-hosting config pages that + the docs app builds from config files, because the suite only resolves MDX + guides. This is a known limitation. ### Limits @@ -165,9 +170,13 @@ staged and unstaged working-tree changes. ## Accessibility scans -The `@a11y`-tagged test scans each in-scope page for WCAG 2.1 A/AA violations using -`@axe-core/playwright`, limited to the main article. The scans are slow, so CI -runs skip them. +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`. ```bash PLAYWRIGHT_BASE_URL=https://supabase.com pnpm e2e:docs:a11y diff --git a/e2e/docs/utils/resolve-docs-scope.test.ts b/e2e/docs/utils/resolve-docs-scope.test.ts index 310f58e2645..63ea897b18c 100644 --- a/e2e/docs/utils/resolve-docs-scope.test.ts +++ b/e2e/docs/utils/resolve-docs-scope.test.ts @@ -50,6 +50,25 @@ test('excludes a guide that the navigation disables from the full run', async () assert.ok(!pages.includes('/docs/guides/ai-tools/agent-feedback')) }) +test('skips a guide that redirects out of the docs', async () => { + const result = await resolveDocsScope({ + changedFiles: [ + 'apps/docs/content/guides/getting-started/features.mdx', + 'apps/docs/content/guides/ai-tools/mcp.mdx', + ], + repoRoot, + }) + + assert.deepEqual(result.pages, ['/docs/guides/ai-tools/mcp']) +}) + +test('excludes a guide that redirects out of the docs from the full run', async () => { + const pages = await resolveAllDocsPages(repoRoot) + + assert.ok(pages.includes('/docs/guides/ai-tools/mcp')) + assert.ok(!pages.includes('/docs/guides/getting-started/features')) +}) + test('keeps every page in a large change', async () => { const changedFiles = Array.from( { length: 82 }, diff --git a/e2e/docs/utils/resolve-docs-scope.ts b/e2e/docs/utils/resolve-docs-scope.ts index 2be9f2d41e1..77444167039 100644 --- a/e2e/docs/utils/resolve-docs-scope.ts +++ b/e2e/docs/utils/resolve-docs-scope.ts @@ -15,6 +15,7 @@ const GUIDES_PREFIX = 'apps/docs/content/guides/' const PARTIALS_PREFIX = 'apps/docs/content/_partials/' const DOCS_GUIDES_URL_PREFIX = '/docs/guides/' const FEDERATED_CONTENT_SOURCES_DIR = 'apps/docs/scripts/federated-content/sources' +const STATIC_REDIRECTS_FILE = 'apps/docs/lib/redirects/static-redirects.json' export const GUIDE_LIST_COMPONENT = 'apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideListItems.tsx' @@ -27,6 +28,20 @@ export const GUIDE_LIST_COMPONENT_PAGES = [ // the nav disables these guides, so the docs app returns 404 for their html page const NAV_DISABLED_PAGES = new Set(['/docs/guides/ai-tools/agent-feedback']) +// guides with no docs article to test: nav-disabled guides, and guides that redirect elsewhere +async function loadUntestablePages(repoRoot: string): Promise> { + const redirects: unknown = JSON.parse( + await readFile(join(repoRoot, STATIC_REDIRECTS_FILE), 'utf8') + ) + if (!Array.isArray(redirects)) { + throw new Error(`${STATIC_REDIRECTS_FILE} should be an array of redirects.`) + } + const redirectedPages = redirects.flatMap((redirect) => + typeof redirect?.source === 'string' ? [redirect.source] : [] + ) + return new Set([...NAV_DISABLED_PAGES, ...redirectedPages]) +} + const PARTIAL_PATH_RE = /<\$Partial\b[\s\S]*?\bpath\s*=\s*"([^"]+)"[\s\S]*?\/?>/g const SOURCE_SECTION_RE = /\bsection:\s*'([^']+)'/g @@ -266,8 +281,9 @@ export async function resolveDocsScope( } } + const untestablePages = await loadUntestablePages(options.repoRoot) const sorted = [...new Set([...requiredPages, ...pages])] - .filter((page) => !NAV_DISABLED_PAGES.has(page)) + .filter((page) => !untestablePages.has(page)) .sort() return { @@ -282,12 +298,13 @@ export async function resolveAllDocsPages(repoRoot: string): Promise { const guidesDir = join(repoRoot, 'apps/docs/content/guides') const guideFiles = await walkMdxFiles(guidesDir).catch(() => [] as string[]) + const untestablePages = await loadUntestablePages(repoRoot) const pages = new Set() for (const file of guideFiles) { const relFromGuides = normalizeRepoPath(relative(guidesDir, file)).replace(/\.mdx$/, '') const page = `${DOCS_GUIDES_URL_PREFIX}${relFromGuides}` - if (isFederatedGuideSlug(relFromGuides) || NAV_DISABLED_PAGES.has(page)) continue + if (isFederatedGuideSlug(relFromGuides) || untestablePages.has(page)) continue pages.add(page) }