FE-1457: Point source links at the branch being built - #9267
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit d13c8d3. Bugbot is set up for automated code reviews on this repo. Configure here. |
3784d1f to
ee92518
Compare
ee92518 to
621b82c
Compare
621b82c to
0e56bd5
Compare
0e56bd5 to
f7810b2
Compare
f7810b2 to
bd0636e
Compare
bd0636e to
5c8641b
Compare
5c8641b to
d13c8d3
Compare
🌟 What is the purpose of this PR?
Every generated page links to the file that declared its layer, and the link target was hardcoded to
main. On a preview build those links showed the pre-change file, or 404'd for a file the branch adds. The ref now comes from the build environment:In stack #9280, FE-1456 (#9266) sits below and FE-1455 (#9268) above.
🔗 Related links
🔍 What does this change?
src/source-url.ts(new): resolves the ref from the first variable that holds a value, in orderPETRINAUT_ARCH_DOCS_SOURCE_REF,VERCEL_GIT_COMMIT_SHA,GITHUB_SHA,VERCEL_GIT_COMMIT_REF,GITHUB_HEAD_REF,GITHUB_REF_NAME, defaulting tomain. A SHA beats a branch name because the link still resolves after the branch moves or is deleted. Slashes stay literal, since they separate path segments in a blob URL, while#and%are encoded.architecture.config.ts:sourceUrlPrefixcalls the resolver. No literalmainremains.turbo.json: the six variables are declared indoc:architecture'senv, since Turborepo's strict env mode would otherwise hide them from the task.vercel-build.shand the generator's "Wrote" line both name the resolved ref, so a preview build's log shows which commit its links point at..github/workflows/builds the bundle, and GitHub Actions exports the variables the resolver reads.Review fixes
encodeRefdrops empty and dot-only segments. Git refnames forbid them, so they can only arrive through a mistyped override, whereblob//main/or a traversing URL would be worse than a wrong ref.hashintel/hash: on a fork PR,GITHUB_HEAD_REFnames a branch this repository does not have and the link 404s, while the SHA variables win when present and resolve regardless.REF_VARIABLESandturbo.json'senvlist cross-reference each other, with a comment on each side saying to keep the two lists identical.Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
turbo.json's have been updated to reflect thisdoc:architecturedeclares the ref variables. The task and its consumers are uncached, so a ref change cannot serve stale links.🛡 What tests cover this?
source-url.test.ts: the default, blank values skipped, SHA over branch for both providers, the local override over both, a branch name containing a slash, and#encoding.❓ How to test this?
yarn workspace @local/petrinaut-arch-docs doc:architectureand grep adeclaredInUrlinbundle/pages/architecture/cli.mdx: it points atblob/main/.GITHUB_HEAD_REF=<a branch>: the same link points at that branch. AddingGITHUB_SHA=<sha>switches it to the SHA.🐾 Next steps
Two hand-written
blob/main/...links remain in authored MDX. Those name specific files as references rather than being generated source links; giving them the same treatment needs a link helper in the authoring syntax.🤖 Generated with Claude Code