ci: limit blog Markdown link checks to newly added posts - #1345
Open
MFA-G wants to merge 1 commit into
Open
Conversation
|
Contributor
|
Caution Review failedAn error occurred during the review process. Please try again later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Siddhant-K-code
left a comment
Member
There was a problem hiding this comment.
@MFA-G, Can you sign the CLA
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.
Fixes #1344.
The problem
markdown-link-check-mdandmarkdown-link-checkwalk the repository root, so every run checks all 24 posts inblog/. Those posts are point-in-time announcements —kubecon-na-2023.md, the monthlyfine-grained-news-*roundups — and their external links rot on their own schedule. When one does, the failure lands on whatever unrelated PR happens to run next, which is what prompted the request in #1341.The change
Blog posts are checked when a PR adds them, and not otherwise.
folder-path: 'docs', so they no longer descend intoblog/.markdown-link-check-rootkeeps the rootREADME.mdcovered —folder-path: docswould otherwise drop it, so it getsmax-depth: 1.markdown-link-check-new-blog-postsrunsscripts/new-blog-posts.mjsto list the posts the branch adds and, only when there are some, runsmarkdown-link-checkover exactly those files. Non-blog content is untouched.scripts/new-blog-posts.mjsis deliberately small: it asks git for--diff-filter=A <base>...HEAD -- blog, then keepsblog/*.{md,mdx}. Two details are load-bearing:--diff-filter=A— a modification is not an addition, so editing an existing post never puts its historical links on trial.<base>...HEAD— the diff is against the merge base. A two-dot diff would report posts that landed onmainafter the branch forked as if the branch had added them, and a stale branch would then fail on someone else's post.Acceptance criteria
markdown-link-checkexits 123reports nothing when the branch only edits an existing postif: steps.new-posts.outputs.files != '', plusreports nothing for a branch that touches no blog postsgithub.base_ref;preview.ymlis a separate workflow and is unchangedscripts/new-blog-posts.test.mjs, 11 testsValidation
Tests use
node:test(no new dependency) and drive a real temporary git repository rather than a stubbedgit, since the criteria are about what a branch produces. Added asnpm test, wired into thebuildjob.The CLI, driven against real branches in this checkout:
And the workflow's link-check step, run verbatim:
npx eslint scripts/andnpx prettier --checkare clean.Note
markdown-link-check-new-blog-postsneedsfetch-depth: 0for the merge-base diff. If you would rather avoid the full clone,fetch-depth: 0can be dropped in favour of an explicitgit fetch --deepen— happy to switch. I also kept the root README on its own job rather than folding it into afolder-path: 'docs,.'list, because.would re-includeblog/; if you would prefer a different split, let me know.