Skip to content

ci: fail PRs that break redirects - #1880

Draft
marcleblanc2 wants to merge 1 commit into
mainfrom
check-redirects
Draft

ci: fail PRs that break redirects#1880
marcleblanc2 wants to merge 1 commit into
mainfrom
check-redirects

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

What

A PR check that fails when the PR breaks a redirect in src/data/redirects.ts. Companion to the "Check links" workflow (#1874's sibling on check-links-pr-check) and built the same way.

dev/check-redirects.mjs validates every reachable entry:

Problem Example cause
destination page does not exist PR deletes or renames a page that a redirect points at, or a new redirect has a typo
heading #x not found on destination PR renames a heading that a #fragment redirect points at
source is an existing page a new redirect would send visitors away from a page that exists

Chains are followed to the final page; external (http) destinations are skipped. Duplicate sources after the first are ignored, since the middleware only ever uses the first.

.github/workflows/check-redirects.yml runs the script on the merge base and on the PR head and reports only findings the PR introduces. main currently has 227 broken redirects (175 missing destinations, 52 missing headings); those are recorded as a baseline so they don't block unrelated PRs. It posts the report as a PR comment, updates that comment on later pushes, and fails the job.

Also adds pnpm check-redirects for running it locally (--format text|json|markdown, --root, --baseline).

Verification

Ran locally against the flow the workflow uses:

  • Baseline on origin/main (still the module.exports form of redirects.ts): 227 findings, exit 1, JSON written.
  • Current branch vs. baseline: ✅ No redirects broken by this PR, exit 0.
  • Simulated PR in a copy of the repo that deleted docs/batch-changes/permissions-in-batch-changes.mdx, renamed # Cody Quickstart, and added a redirect to /code-ownershp: 5 findings vs. baseline, all correctly attributed with line numbers, exit 1.

The workflow itself runs on this PR, so its result shows below.

Not included

Detecting a page deleted without any redirect (inbound links break, but no redirect entry is involved). That's a different check; happy to add it as a follow-up.

Add dev/check-redirects.mjs, which validates every entry in
src/data/redirects.ts: the destination page exists under docs/ (following
chains through other redirects), a #fragment destination names a heading
that exists on that page, and the source does not shadow an existing page.

Add a Check redirects workflow that runs the script on the PR head and on
the merge base and fails only on findings the PR introduces, so the 227
redirects already broken on main do not block unrelated PRs. It comments
the report on the PR and updates that comment on later pushes, matching
the Check links workflow.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a07e6f-db41-74af-bbeb-f8952e637289
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 8, 2026 1:50am UTC

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant