Add check-links PR check - #1858
Open
marcleblanc2 wants to merge 7 commits into
Open
Conversation
Add a pull_request workflow that runs dev/check-links.mjs --check-anchors on both the PR head and its merge base, and reports only the findings the PR introduces: outbound links from changed pages, and inbound links from other pages to a page or heading the PR removed or renamed. Pre-existing broken anchors on main are ignored. The job comments on the PR and fails when new breakage is found. dev/check-links.mjs gains --root, --format (text|json|markdown) and --baseline to support that diff, plus case-mismatch detection for routes (links that resolve on macOS but 404 on Linux) and scanning of *.md files. Only *.mdx files count as routes, matching contentlayer's filePathPattern. Amp-Thread-ID: https://ampcode.com/threads/T-01a0753f-0f4f-7478-b36c-87466e7c0261 Co-authored-by: Amp <amp@ampcode.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
check-links PR check
…erted) Amp-Thread-ID: https://ampcode.com/threads/T-01a0753f-0f4f-7478-b36c-87466e7c0261 Co-authored-by: Amp <amp@ampcode.com>
…l be reverted)" This reverts commit 1edcff8.
Generated pages such as admin/telemetry/protocol.mdx define anchors with <a name="..."> rather than headings. Drops 132 false positives on main (431 -> 299 with --check-anchors). Amp-Thread-ID: https://ampcode.com/threads/T-01a0753f-0f4f-7478-b36c-87466e7c0261 Co-authored-by: Amp <amp@ampcode.com>
Replace the fs.existsSync asset checks (case-insensitive on macOS, so they
hid links that 404 on the Linux build) with an enumerated lowercase -> real
path map of files under public/ and docs/, mirroring the route check.
Also register docs/index.mdx as the / route. It was never in the path map
(the /index strip needed a leading slash), and existsSync('public/') was
masking that by accepting any '/' link. Six pre-existing broken /#anchor
links on the homepage are now reported.
Amp-Thread-ID: https://ampcode.com/threads/T-01a07597-43c0-751b-8c49-6e5809e714d2
Co-authored-by: Amp <amp@ampcode.com>
A green run posts nothing. If an earlier run left a report and the PR has since been fixed, delete that comment instead of editing it to a checkmark. Amp-Thread-ID: https://ampcode.com/threads/T-01a07597-43c0-751b-8c49-6e5809e714d2 Co-authored-by: Amp <amp@ampcode.com>
The checkmark comment only ever appears after an earlier run reported breakage, so word it that way instead of "introduces no broken links". Keeps the comment (reverts the delete from the previous commit). Amp-Thread-ID: https://ampcode.com/threads/T-01a07597-43c0-751b-8c49-6e5809e714d2 Co-authored-by: Amp <amp@ampcode.com>
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.
Problem
dev/check-links.mjscan find broken internal links and anchors, but nothing runs it, so PRs regularly break links (renaming a heading, moving or deleting a page) without anyone noticingSolution
A
pull_requestworkflow that reports only the breakage a PR introduces, and comments on the PR when there is any.It runs the checker (with
--check-anchors) on both the PR head and its merge base, and diffs the findings. That catches both directions:#headingthat doesn't existPre-existing broken links on
mainare ignored, so the check is green today and only fails when a PR makes things worse. The comment is created or updated in place (one comment per PR), and once the PR is fixed it is updated to say so. A PR that never broke anything gets no comment. Fork PRs get a read-only token, so for those the report is only in the job log.Changes to
dev/check-links.mjs--root <dir>: check another checkout (used for the merge base)--format text|json|markdown:jsonfor the baseline,markdownfor the PR comment--baseline <file>: report only findings absent from a previousjsonrun/Code-Search/foowhen the route is/code-search/foo, or/Img/Foo.pngwhen the file ispublic/img/foo.png— resolves on macOS, 404s on the Linux build. Assets underpublic/anddocs/are enumerated into a map for this, replacingfs.existsSync(which is case-insensitive on macOS).*.mdas well as*.mdxfor outbound links. Only.mdxfiles count as valid routes, matchingfilePathPatternincontentlayer.config.ts, so a link to a.mdfile is reported as a missing page.<a name="…">/id="…"attributes as anchor targets, as used by the generatedadmin/telemetry/protocol.mdxfileVerification
Local simulation of a PR that renames
## Search contextsincode-search/features.mdx, deletesadmin/telemetry/protocol.mdx, adds bad outbound links and a case-mismatched link, and adds a.mdfile with a broken link. The report listed exactly those 12 new findings (4 inbound-anchor, 3 inbound-page, 4 outbound, 1 in the.md) and none of the 431 pre-existing ones.Also
actionlint,prettier --checkon the workflow, andbash -non each step.Related