diff --git a/.github/workflows/docs-a11y-scan.yml b/.github/workflows/docs-a11y-scan.yml
index 8512df32c62..22aa9744614 100644
--- a/.github/workflows/docs-a11y-scan.yml
+++ b/.github/workflows/docs-a11y-scan.yml
@@ -1,5 +1,5 @@
# Scans every docs guide on production for accessibility violations, daily.
-# docs-master-alert.yml posts failures to Slack.
+# docs-master-alert.yml posts to Slack when its list of failures changes.
name: Docs Accessibility Scan
@@ -58,6 +58,17 @@ jobs:
run: pnpm run e2e:docs:all --grep @a11y
env:
PLAYWRIGHT_BASE_URL: https://supabase.com
+ DOCS_A11Y_FAILURES_FILE: ${{ github.workspace }}/e2e/docs/a11y-failures.json
+
+ - name: Upload failures for the alert
+ # docs-alert.ts reads this file through RESULTS_WORKFLOWS
+ if: always()
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: docs-failures-${{ github.run_attempt }}
+ path: e2e/docs/a11y-failures.json
+ retention-days: 7
+ if-no-files-found: ignore
- name: Upload Playwright report
if: failure()
diff --git a/.github/workflows/docs-master-alert.yml b/.github/workflows/docs-master-alert.yml
index 6ba6c32926d..c0c308ee98a 100644
--- a/.github/workflows/docs-master-alert.yml
+++ b/.github/workflows/docs-master-alert.yml
@@ -1,3 +1,7 @@
+# Keeps a list of open failures for each docs workflow below, and posts to Slack when the list
+# changes. Each failure names the commit that introduced it, or its possible commits. Docs E2E Tests
+# reaches master only through a manual run. e2e/docs/scripts/docs-alert.ts holds the logic.
+
name: Alert on master breakage
on:
@@ -7,13 +11,10 @@ on:
- '[Docs] Update last-changed dates'
- 'Update JS Client Libraries Docs'
- 'Update Mgmt Api Docs'
- - 'Docs Navigation Checks'
- - 'Docs removed anchors'
- 'docs_sync'
- 'Docs Production Smoke Tests'
- 'Docs Accessibility Scan'
- 'Ingest Docs Content for Search V2'
- - 'Docs Tests'
branches: [master]
types:
- completed
@@ -21,44 +22,70 @@ on:
permissions:
contents: read
actions: read
+ statuses: read
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.workflow_run.workflow_id }}
+ cancel-in-progress: false
jobs:
notify:
- if: ${{ github.event.workflow_run.conclusion == 'failure' }}
+ if: >-
+ github.event.workflow_run.head_repository.full_name == github.repository &&
+ (github.event.workflow_run.conclusion == 'success' ||
+ github.event.workflow_run.conclusion == 'failure')
runs-on: ubuntu-latest
+ env:
+ STATE_NAME: docs-open-failures-${{ github.event.workflow_run.workflow_id }}
steps:
- - name: Send Slack alert
- env:
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DOCS_WEBHOOK_URL }}
- WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
- WORKFLOW_URL: ${{ github.event.workflow_run.html_url }}
- TRIGGER: ${{ github.event.workflow_run.event }}
- run: |
- PAYLOAD=$(jq -n \
- --arg workflow_name "$WORKFLOW_NAME" \
- --arg workflow_url "$WORKFLOW_URL" \
- --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: \($workflow_name) failed"
- }
- },
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: "*Workflow:* <\($workflow_url)|\($workflow_name)> (\($run))"
- }
- }
- ]
- }')
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
+ with:
+ persist-credentials: false
+ sparse-checkout: |
+ e2e/docs
+ e2e/shared
+ apps/docs/content
- curl -f -X POST "$SLACK_WEBHOOK_URL" \
- -H 'Content-Type: application/json' \
- -d "$PAYLOAD"
+ - name: Use Node.js
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
+ with:
+ node-version-file: '.nvmrc'
+
+ - name: Download the saved list and the run's results
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ RUN_ID: ${{ github.event.workflow_run.id }}
+ RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
+ run: |
+ mkdir -p "$RUNNER_TEMP/state-in" "$RUNNER_TEMP/state-out" "$RUNNER_TEMP/results"
+ # Only trust a saved list from a master run in this repo, not from a fork or a branch
+ ID=$(gh api "repos/$REPO/actions/artifacts?name=$STATE_NAME&per_page=100" \
+ --jq '[.artifacts[] | select((.expired | not)
+ and .workflow_run.head_branch == "master"
+ and .workflow_run.head_repository_id == .workflow_run.repository_id)]
+ | max_by(.created_at) | .id // empty')
+ if [ -n "$ID" ]; then
+ gh api "repos/$REPO/actions/artifacts/$ID/zip" > "$RUNNER_TEMP/state.zip"
+ unzip -o -q "$RUNNER_TEMP/state.zip" open-failures.json -d "$RUNNER_TEMP/state-in"
+ fi
+ gh run download "$RUN_ID" --repo "$REPO" --name "docs-failures-$RUN_ATTEMPT" \
+ --dir "$RUNNER_TEMP/results" || echo "No results artifact on this run."
+
+ - name: Update the list and post changes
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DOCS_WEBHOOK_URL }}
+ run: |
+ STATE_IN="$RUNNER_TEMP/state-in/open-failures.json" \
+ STATE_OUT="$RUNNER_TEMP/state-out/open-failures.json" \
+ RESULTS_DIR="$RUNNER_TEMP/results" \
+ node --experimental-strip-types e2e/docs/scripts/docs-alert.ts
+
+ - name: Save the list
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: ${{ env.STATE_NAME }}
+ path: ${{ runner.temp }}/state-out/open-failures.json
+ retention-days: 90
+ if-no-files-found: ignore
diff --git a/.github/workflows/docs-tests-smoke.yml b/.github/workflows/docs-tests-smoke.yml
index d5ff5297ccf..ede7fe00ec2 100644
--- a/.github/workflows/docs-tests-smoke.yml
+++ b/.github/workflows/docs-tests-smoke.yml
@@ -43,4 +43,14 @@ jobs:
run: pnpm install --frozen-lockfile
- name: Run tests
- run: pnpm --prefix="apps/docs" run test:smoke
+ run: pnpm --prefix="apps/docs" run test:smoke --reporter=default --reporter=json --outputFile.json=smoke-results.json
+
+ - name: Upload results for the alert
+ # docs-alert.ts reads this file through RESULTS_WORKFLOWS
+ if: always()
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: docs-failures-${{ github.run_attempt }}
+ path: apps/docs/smoke-results.json
+ retention-days: 7
+ if-no-files-found: ignore
diff --git a/e2e/docs/README.md b/e2e/docs/README.md
index e1507a6c9c0..81bc4d23c62 100644
--- a/e2e/docs/README.md
+++ b/e2e/docs/README.md
@@ -21,6 +21,7 @@ This page covers:
- [Accessibility scans](#accessibility-scans) — WCAG coverage and skipped rules
- [Debug failures](#debug-failures) — reports and traces
- [How CI uses this suite](#how-ci-uses-this-suite) — pull request behavior
+- [Failure alerts](#failure-alerts) — Slack alerts for docs workflows on `master`
## Set up
@@ -172,11 +173,16 @@ staged and unstaged working-tree changes.
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.
+`ENFORCED_RULES` in `utils/axe-rules.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`.
+production daily at 05:17 UTC. To start it by hand, run
+`gh workflow run docs-a11y-scan.yml`.
+
+When the daily scan finds a new failure or a fix, it posts to the docs alerts
+channel in Slack. See [Failure alerts](#failure-alerts).
+
+To run the scan locally:
```bash
PLAYWRIGHT_BASE_URL=https://supabase.com pnpm e2e:docs:a11y
@@ -187,7 +193,7 @@ whatever you point `PLAYWRIGHT_BASE_URL` at. Production won't have your edits an
will 404 on a page you just added, so use your pull request's preview to scan your
own content.
-`EXCLUDED_RULES` in `utils/axe-helpers.ts` lists the rules the scan skips.
+`EXCLUDED_RULES` in `utils/axe-rules.ts` lists the rules the scan skips.
`color-contrast` is most of the scan time and finds nothing inside an article, since
docs contrast comes from shared tokens and chrome. The rest target ``, `
`,
and ``, which an article-scoped scan can't reach.
@@ -227,3 +233,34 @@ owned docs content, partials, or `e2e/docs`.
Draft pull requests stay skipped until you mark them ready for review. Manual
`workflow_dispatch` runs require a `page_paths` input and accept an optional
`base_url`, which defaults to production.
+
+## Failure alerts
+
+`.github/workflows/docs-master-alert.yml` keeps a list of open failures for each
+of the following workflows when they run on `master`:
+
+- Docs Accessibility Scan, with one failure per page and axe rule
+- Docs Production Smoke Tests, with one failure per test
+- Docs E2E Tests, which runs on `master` only when started by hand
+- [Docs] Update last-changed dates
+- Update JS Client Libraries Docs
+- Update Mgmt Api Docs
+- docs_sync
+- Ingest Docs Content for Search V2
+
+For the workflows without their own results, each failed job or step is one
+failure.
+
+| When | The alert |
+| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
+| A failure is added | Posts it with the commit that introduced it, or the possible commits |
+| A failure is fixed | Posts the fix |
+| The list doesn't change | Posts nothing |
+| A page or test times out, a page doesn't render, or a job or step is skipped | Keeps its earlier result |
+| A page returns an error status, such as 404 | Counts a failure for that status in place of any earlier one, and keeps the page's earlier scan results |
+| No smoke test passes and some time out | Counts one failure for the run |
+| A run fails before it reports results | Posts that the run failed, and keeps the list as it was |
+
+For the scan, a new failure names the deployed commit that touched the page or a
+partial it includes. When no single commit did, the alert lists the possible
+commits as unconfirmed.
diff --git a/e2e/docs/playwright.config.ts b/e2e/docs/playwright.config.ts
index 84f934b3e29..7baa6278550 100644
--- a/e2e/docs/playwright.config.ts
+++ b/e2e/docs/playwright.config.ts
@@ -6,6 +6,8 @@ const IS_CI = !!process.env.CI
const PAGE_COUNT = parsePagePaths(process.env.DOCS_E2E_PAGE_PATHS).length
+const A11Y_FAILURES_FILE = process.env.DOCS_A11Y_FAILURES_FILE
+
export default defineConfig({
testDir: './features',
testMatch: /.*\.spec\.ts/,
@@ -42,12 +44,13 @@ export default defineConfig({
},
},
],
- reporter: IS_CI
- ? [['list'], ['html', { open: 'never', outputFolder: './playwright-report' }]]
- : [
- ['list'],
- ['html', { open: 'never', outputFolder: './playwright-report' }],
- ['json', { outputFile: './test-results/test-results.json' }],
- ],
+ reporter: [
+ ['list'],
+ ['html', { open: 'never', outputFolder: './playwright-report' }],
+ ...(IS_CI ? [] : [['json', { outputFile: './test-results/test-results.json' }] as const]),
+ ...(A11Y_FAILURES_FILE
+ ? [['./utils/a11y-failures-reporter.ts', { outputFile: A11Y_FAILURES_FILE }] as const]
+ : []),
+ ],
outputDir: './test-results',
})
diff --git a/e2e/docs/scripts/docs-alert.ts b/e2e/docs/scripts/docs-alert.ts
new file mode 100644
index 00000000000..d9f76a60eec
--- /dev/null
+++ b/e2e/docs/scripts/docs-alert.ts
@@ -0,0 +1,441 @@
+#!/usr/bin/env node
+// Keeps the open-failures list for a docs workflow run on master and posts to Slack when it
+// changes. Run by .github/workflows/docs-master-alert.yml.
+import { existsSync, readFileSync, writeFileSync } from 'node:fs'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import {
+ attribute,
+ baselineFor,
+ compareFailures,
+ deployedCommitsBetween,
+ failuresFromJobs,
+ failuresFromVitest,
+ formatAlert,
+ formatCrashAlert,
+ nextLastChecked,
+ parseFailureState,
+ parseRunFailures,
+ pushCandidates,
+ stateFromPassingRun,
+ titleOf,
+ type ActionsJob,
+ type ActionsRun,
+ type Attribution,
+ type Commit,
+ type Failure,
+ type FailureState,
+ type HistoryCommit,
+ type OpenFailure,
+ type RunFailures,
+ type RunRef,
+} from '../utils/open-failures.ts'
+import { pageSourceFiles } from '../utils/resolve-docs-scope.ts'
+
+const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '../../..')
+
+// Workflows that test production and upload their results as the `docs-failures-`
+// artifact (see the upload steps in docs-a11y-scan.yml and docs-tests-smoke.yml)
+const RESULTS_WORKFLOWS: Record<
+ string,
+ { file: string; narrowToPage: boolean; parse: (report: unknown) => RunFailures | null }
+> = {
+ '.github/workflows/docs-a11y-scan.yml': {
+ file: 'a11y-failures.json',
+ narrowToPage: true,
+ parse: parseRunFailures,
+ },
+ '.github/workflows/docs-tests-smoke.yml': {
+ file: 'smoke-results.json',
+ narrowToPage: false,
+ parse: failuresFromVitest,
+ },
+}
+
+const VERCEL_STATUS_CONTEXT = 'Vercel – docs'
+const HISTORY_PADDING_MS = 3 * 24 * 60 * 60 * 1000
+const NEVER_CHECKED: Attribution = {
+ kind: 'none',
+ reason: 'no earlier run checked this since tracking started',
+}
+
+type WorkflowRun = ActionsRun & {
+ id: number
+ run_attempt: number
+ name: string
+ path: string
+ event: string
+ run_started_at: string
+ updated_at: string
+ html_url: string
+ workflow_id: number
+}
+
+const env = (name: string, fallback?: string): string => {
+ const value = process.env[name] ?? fallback
+ if (value === undefined) throw new Error(`${name} is not set.`)
+ return value
+}
+
+const repo = env('GITHUB_REPOSITORY')
+const token = env('GITHUB_TOKEN')
+const apiUrl = env('GITHUB_API_URL', 'https://api.github.com')
+const repoUrl = `${env('GITHUB_SERVER_URL', 'https://github.com')}/${repo}`
+
+// Response shapes follow GitHub's documented REST and GraphQL schemas
+async function github(path: string, init?: RequestInit): Promise {
+ const response = await fetch(`${apiUrl}${path}`, {
+ ...init,
+ headers: {
+ Accept: 'application/vnd.github+json',
+ Authorization: `Bearer ${token}`,
+ 'X-GitHub-Api-Version': '2022-11-28',
+ ...init?.headers,
+ },
+ })
+ if (!response.ok) {
+ throw new Error(`GitHub API ${path} returned ${response.status}: ${await response.text()}`)
+ }
+ return (await response.json()) as T
+}
+
+function readJson(path: string | undefined): unknown {
+ if (!path || !existsSync(path)) return null
+ try {
+ return JSON.parse(readFileSync(path, 'utf8'))
+ } catch {
+ return null
+ }
+}
+
+function toRunRef(run: WorkflowRun): RunRef {
+ return {
+ id: run.id,
+ attempt: run.run_attempt,
+ runNumber: run.run_number,
+ headSha: run.head_sha,
+ startedAt: run.run_started_at,
+ }
+}
+
+function runLabel(event: string): string {
+ if (event === 'push') return 'push to master'
+ if (event === 'schedule') return 'scheduled run'
+ if (event === 'workflow_dispatch') return 'manual run'
+ return `${event} run`
+}
+
+async function jobFailures(run: WorkflowRun): Promise {
+ const { jobs } = await github<{ jobs: ActionsJob[] }>(
+ `/repos/${repo}/actions/runs/${run.id}/attempts/${run.run_attempt}/jobs?per_page=100`
+ )
+ return failuresFromJobs(jobs)
+}
+
+// null when the run's results are missing or unreadable, so this run can't change the list
+async function currentFailures(run: WorkflowRun, resultsDir: string): Promise {
+ const results = RESULTS_WORKFLOWS[run.path]
+ if (results) return results.parse(readJson(join(resultsDir, results.file)))
+
+ // Read jobs on a passing run too, so a step its condition skipped keeps its earlier result
+ const fromJobs = await jobFailures(run)
+ if (run.conclusion === 'success' || fromJobs.failures.length > 0) return fromJobs
+ return { failures: [{ key: 'run' }], unchecked: fromJobs.unchecked }
+}
+
+// With no saved list, a previous run that passed still says nothing was open
+async function baselineFromApi(run: WorkflowRun): Promise {
+ const { workflow_runs: runs } = await github<{ workflow_runs: WorkflowRun[] }>(
+ `/repos/${repo}/actions/workflows/${run.workflow_id}/runs?branch=master&status=completed&per_page=20`
+ )
+ const previous = runs.find(
+ (candidate) =>
+ candidate.event !== 'pull_request' &&
+ candidate.run_number < run.run_number &&
+ (candidate.conclusion === 'success' || candidate.conclusion === 'failure')
+ )
+ if (previous?.conclusion !== 'success') return null
+ // A results workflow's earlier artifact isn't read here, so its skipped pages count as checked
+ const skipped = RESULTS_WORKFLOWS[run.path] ? [] : (await jobFailures(previous)).unchecked
+ return stateFromPassingRun(toRunRef(previous), skipped)
+}
+
+async function deployHistory(since: string): Promise {
+ const [owner, name] = repo.split('/')
+ const query = `query($owner: String!, $name: String!, $since: GitTimestamp!, $cursor: String) {
+ repository(owner: $owner, name: $name) {
+ ref(qualifiedName: "refs/heads/master") {
+ target {
+ ... on Commit {
+ history(first: 100, since: $since, after: $cursor) {
+ pageInfo { hasNextPage endCursor }
+ nodes {
+ oid
+ messageHeadline
+ status { context(name: "${VERCEL_STATUS_CONTEXT}") { state description createdAt } }
+ }
+ }
+ }
+ }
+ }
+ }
+ }`
+
+ type Page = {
+ data: {
+ repository: {
+ ref: {
+ target: {
+ history: {
+ pageInfo: { hasNextPage: boolean; endCursor: string }
+ nodes: {
+ oid: string
+ messageHeadline: string
+ status: { context: HistoryCommit['status'] } | null
+ }[]
+ }
+ }
+ }
+ }
+ }
+ }
+
+ const commits: HistoryCommit[] = []
+ let cursor: string | null = null
+ for (let page = 0; page < 5; page++) {
+ const result: Page = await github('/graphql', {
+ method: 'POST',
+ body: JSON.stringify({ query, variables: { owner, name, since, cursor } }),
+ })
+ const history = result.data.repository.ref.target.history
+ for (const node of history.nodes) {
+ commits.push({
+ sha: node.oid,
+ title: node.messageHeadline,
+ status: node.status?.context ?? null,
+ })
+ }
+ if (!history.pageInfo.hasNextPage) break
+ cursor = history.pageInfo.endCursor
+ }
+ return commits
+}
+
+async function pushRange(run: WorkflowRun, baseline: RunRef): Promise {
+ const runs: WorkflowRun[] = []
+ for (let page = 1; ; page++) {
+ const { workflow_runs: batch } = await github<{ workflow_runs: WorkflowRun[] }>(
+ `/repos/${repo}/actions/workflows/${run.workflow_id}/runs?branch=master&event=push&created=>=${baseline.startedAt.slice(0, 10)}&per_page=100&page=${page}`
+ )
+ runs.push(...batch)
+ // Runs come newest first, so stop once a page reaches back to the baseline
+ if (batch.length < 100 || batch.some((item) => item.run_number <= baseline.runNumber)) break
+ }
+ return pushCandidates(runs, baseline.runNumber, run)
+}
+
+type CommitRange = { commits: Commit[]; total: number }
+
+type Comparison = {
+ total_commits: number
+ commits: { sha: string; commit: { message: string } }[]
+}
+
+// The compare API lists the oldest commits first and returns at most 250, so a longer range
+// fetches its last two pages of 100 to list the newest commits
+async function compareRange(base: string, head: string): Promise {
+ if (base === head) return { commits: [], total: 0 }
+ const path = `/repos/${repo}/compare/${base}...${head}`
+ const first = await github(`${path}?per_page=250`)
+ let commits = first.commits
+ if (first.total_commits > commits.length) {
+ const lastPage = Math.ceil(first.total_commits / 100)
+ const pages = await Promise.all(
+ [lastPage - 1, lastPage].map((page) =>
+ github(`${path}?per_page=100&page=${page}`)
+ )
+ )
+ commits = pages.flatMap((page) => page.commits)
+ }
+ return {
+ commits: commits.map((commit) => ({
+ sha: commit.sha,
+ title: titleOf(commit.commit.message),
+ })),
+ total: first.total_commits,
+ }
+}
+
+async function attributeNew(
+ run: WorkflowRun,
+ state: FailureState,
+ added: Failure[]
+): Promise