Files
supabase/.github/workflows/docs-removed-anchors.yml
Miranda Limonczenko aec7aed134 ci(docs): fail PRs that remove a linked guide section (#52100)
Closes DOCS-1486

## Problem

Agents are slow to update what they remember about the docs, and nothing
protects a section when it moves to another page.

This leaves a trail when sections move: the PR fails unless the heading
stays with a summary and a link to where the content went.

## Solution

A new `Docs removed anchors` workflow runs `pnpm check:removed-anchors`
from `apps/docs`.

- **What it compares:** H2 and H3 anchors between the base branch and
the PR, only on changed guide pages and pages that include a changed
partial. Partials are expanded, nested ones too.
- **When it fails:** a file anywhere in `apps`, `packages`, or
`examples` still links to a removed anchor. That covers docs content,
Studio, www and the blog, and kb, plus same-page `#anchor` links. Test
files and generated output are skipped. The failure names each anchor
and every linking `file:line`, and annotates those lines.
- **How anchors are computed:** with `getAnchor` from `packages/ui`, the
same function that sets rendered heading ids, so `## Title [#custom-id]`
matches on the custom id.
- **Bypass:** the `skip-anchor-check` label turns the errors into
warnings and passes the check. The failure message names the label and
the fixes.
- **No `paths` filter:** a required check whose workflow never starts
leaves unrelated PRs waiting. The job runs on every PR and exits before
installing anything when docs content is unchanged.

Out of scope: deleted or moved pages, and links from outside this repo.

The workflow checks out text files across `apps`, `packages`, and
`examples`, and skips images and video, so the search doesn't download
them.

The check only blocks merges once it's a required status check on
`master`. That needs a repo admin.

## Skip the check

For a deliberate removal:

1. Add the `skip-anchor-check` label to the PR.
2. The check re-runs and passes. The links it would have failed on show
as warnings.

Remove the label to turn the check back on.

## Manual testing

1. From `apps/docs`, delete `[#leaked-key]` from the heading in
`content/guides/getting-started/api-keys.mdx`.
2. Run `pnpm check:removed-anchors`. It exits 1 and names
`troubleshooting/rotating-anon-service-and-jwt-secrets-1Jq6yd.mdx:39`.
3. Run `PR_LABELS='["skip-anchor-check"]' pnpm check:removed-anchors`.
It prints the same report and exits 0.
4. Run `pnpm vitest run scripts/check-removed-anchors.test.ts`. All
tests pass.
2026-10-29 14:23:13 -07:00

78 lines
2.1 KiB
YAML

name: Docs removed anchors
# Leaves a trail when sections move. See apps/docs/scripts/check-removed-anchors.ts.
on:
pull_request:
branches: ['master']
types: [opened, synchronize, reopened, labeled, unlabeled]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
fetch-depth: 2
sparse-checkout-cone-mode: false
sparse-checkout: |
/*
!*.png
!*.jpg
!*.jpeg
!*.gif
!*.webp
!*.avif
!*.svg
!*.mp4
!*.webm
!*.mov
!*.ico
!*.woff
!*.woff2
!*.ttf
!*.otf
!*.pdf
!*.zip
- name: Check for docs content changes
id: changes
run: |
if git diff --quiet HEAD^1 HEAD -- apps/docs/content; then
echo "No docs content changed."
echo "content=false" >> "$GITHUB_OUTPUT"
else
echo "content=true" >> "$GITHUB_OUTPUT"
fi
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
if: steps.changes.outputs.content == 'true'
name: Install pnpm
with:
run_install: false
- name: Use Node.js
if: steps.changes.outputs.content == 'true'
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install deps
if: steps.changes.outputs.content == 'true'
run: pnpm install --frozen-lockfile --filter docs...
- name: Check removed anchors
if: steps.changes.outputs.content == 'true'
working-directory: apps/docs
env:
PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
run: pnpm check:removed-anchors --base HEAD^1