ci/redirects: Add PR check for broken redirects - #1880
Draft
marcleblanc2 wants to merge 1 commit into
Draft
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 oncheck-links-pr-check) and built the same way.dev/check-redirects.mjsvalidates every reachable entry:#xnot found on destination#fragmentredirect points atChains 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.ymlruns the script on the merge base and on the PR head and reports only findings the PR introduces.maincurrently 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-redirectsfor running it locally (--format text|json|markdown,--root,--baseline).Verification
Ran locally against the flow the workflow uses:
origin/main(still themodule.exportsform ofredirects.ts): 227 findings, exit 1, JSON written.✅ No redirects broken by this PR, exit 0.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.
Amp threads