Repository navigation
Conversation
A PR that removes a docs page must add a redirect, or readers get a 404. Pages under the CLI reference are exempt, because the site redirects a dead reference URL to its nearest parent page, but the reference root is not. An unreadable manifest is reported on its own: invalid JSON, or JSON in a shape the site can't read.
checkRedirects compares a PR's head with its base. A page URL that works on the base and not on the head is an error with a redirect entry to paste, unless it is under the CLI reference. readManifest rejects JSON smallstep.com can't walk, and the error names the bad route.
The check compares a head, the working tree by default, with the merge base of --base and that head, so a branch that is behind main isn't blamed for main's changes. In GitHub Actions it prints annotations and writes the run summary: errors first, then new warnings, then warnings already on the base. Elsewhere it prints a plain list. It exits 1 on any error and 2 when it can't read a revision.
check-redirects.mjs reads each revision with one git cat-file process: the commit's file list, manifest.json and every .mdx file. The working tree is read in place, untracked files included. report.mjs writes annotations, the run summary and a plain list. A full run over the docs repo takes about a quarter of a second.
Every page in the docs manifest sits under a heading route, so R1 checks nothing if the walk stops recursing. Until now only the replays caught that, and they skip in a shallow clone. The spec also says warnings never fail the check, which no test covered. Each new test fails when its behavior is broken.
Git allows a newline in a file name. readCommit sends one <commit>:<path> line per file to git cat-file --batch, so such a name becomes two requests, and every later file gets the text of the one before it. A branch that removes a page can then pass: a decoy file sits where manifest.json is read. These tests fail until contents are read by object id.
readCommit lists the tree with object ids and asks git cat-file --batch for blobs by id, so a file name can no longer reach the batch protocol. Each answer must carry the requested id, be a blob and have a numeric size, and no output may be left over; anything else fails the check with exit 2. Error messages carry object ids, not file names.
Messages quote text from the change: URLs built from manifest paths now, and link targets and file names later. V8's JSON errors also quote the manifest around the bad token, newlines included. On a GitHub runner, a printed line that starts with :: or holds ##[ is a workflow command, so a manifest path can forge annotations in the plain list or in git's error text. The summary is Markdown, where the same text can add links, images or headings. The tests expect: - one line per violation in the plain list; - in Actions, the plain list and stderr wrapped in a stop-commands block; - the change's text in the summary rendered as plain text; - JSON errors that give a position instead of quoting the manifest.
- In GitHub Actions, everything printed besides the annotations sits in a stop-commands block with a random token: the plain list, and the usage and git errors on stderr. The runner then reads none of it as a workflow command. - The plain list and the summary make line breaks visible as ⏎ and replace other control characters, so each violation stays on one line. - The summary escapes all ASCII punctuation in locations and messages, so text from the change renders as written. - A JSON syntax error now gives only its line and column instead of V8's message, which quotes the manifest around the error.
`redirects` in manifest.json must be an array of objects with exactly a string source and a string destination (R2). A source is /docs plus at least one segment, written as smallstep.com matches it (R3). A destination is a docs page in the change, optionally with a fragment (R4). No URL may be both a page and a source (R5), and no source may appear twice (R6). An entry that passes R2–R4 keeps its source working for R1, so removing it, or pointing it at a missing page, fails like removing a page. A problem already on the base is a warning, and so is every finding when the base manifest can't be read.
readSite collects what one revision serves: its pages, plus the sources of redirects that pass R2–R4. That is what R1 compares. It also collects the revision's own problems (R2–R6), each keyed by rule and entry. A problem in the head becomes an error when the base doesn't have its key, and a warning otherwise. Annotations point at the line of the entry's source. An entry with a malformed source gets only R3 and R4, since R5 and R6 can't apply to a URL smallstep.com would never match.
A manifest path whose file doesn't exist is a page smallstep.com can't render (R7). Two manifest paths that map to the same URL, such as /foo.mdx and /foo/README.mdx, make one of them unreachable (R8). Both are errors when the change introduces them and warnings when the base already has them. The test revision now gives every manifest path a file unless a test lists the files itself.
pageFindings reports a manifest path with no file (R7) and a URL that more than one path maps to (R8), each at the line of its "path". The R7 and R8 tests expected the title's line, because the test routes use the path as their title. They now look for the "path" line.
docsLinks reads the docs URLs an .mdx file links to, and the line of each: - inline links, reference definitions, JSX href, and autolinks or bare https://smallstep.com/docs URLs; - skipped: images, footnotes, fenced and inline code, other schemes and hosts, anchors and assets. Each link resolves the way smallstep.com renders it: - Markdown links as remark-relative-links.js rewrites them, against the file's directory; - JSX hrefs as the browser resolves them, since the site leaves them alone; - then the fragment, query string, trailing slash, and trailing /index.html or /README are dropped. It must stay fast on hostile input. A link to a page the change removes fails (R9), even when the change adds a redirect. It only warns when the file is generated under step-cli/reference/. A link to any other non-page is a warning (R9b).
links.mjs reads the links of each .mdx file one line at a time, outside fenced and inline code. Every pattern has bounded repeats: a 100k-character line of "[" takes about 120 ms. How a link resolves: - A Markdown link or definition resolves as remark-relative-links.js rewrites it. - A JSX href resolves from the page URL as a browser would. The site renders JSX untouched, so <a href="./x.mdx"> on /docs/a/b/ leads to /docs/a/b/x.mdx. pageUrl moves to links.mjs, so rules.mjs depends on links.mjs and not the other way round. R9 is an error for a link to a page the change removes, and a warning when a generated reference page has it. R9b warns about any other link to a non-page. On main (247185f) the check reports three existing R9b warnings, not the two the spec expects. The third is tutorials/protect-wired-networks.mdx:30, whose relative JSX href leads to /docs/tutorials/protect-wired-networks/protect-wireless-networks.mdx. smallstep.com answers that URL only through a redirects.js entry.
The step-ci push 5184bd8 removed ten beta/ca reference pages without a redirect, which the reference exemption allows. It fails only for the hand-written link to one of them, at certificate-manager/kubernetes-tls/kubernetes-step-issuer.mdx:31. Main at 247185f has no errors and exactly three existing R9b warnings. A full run over main takes about 0.27 s.
check-redirects.yml is meant to become a required check: - It runs on every pull request, with no paths filter, and on `edited` too, so changing the base branch runs it again. - It checks out the merge commit with fetch-depth 2 and fails if HEAD has no second parent, because only then is HEAD^1 the base branch. - It has a read-only token, no persisted credentials, no secrets and no job-level `if`. A skipped required check counts as passing. check-redirects-tests.yml runs the script's tests when the script or these workflows change. It fetches full history for the replays. Both pin actions/checkout v7.0.1 and actions/setup-node v7.2.0 to commit SHAs and use Node 24. actionlint reports nothing.
smallstep.com serves each entry of a top-level "redirects" array in manifest.json as a 308 (smallstep/smallstep.com#1303). The list starts empty, and each later change that removes a docs URL adds its redirect here. The reference update in smallstep/cli's release workflow replaces only the routes of the node marked isStepReference, so it keeps this key.
CONTRIBUTING.md gets a section on the redirect a change needs when it takes a docs URL away: - the entry format; - that the destination must be a page; - updating links to the old URL in the same pull request; - why reference pages need none; - how to run the check locally, including when origin is a fork. AGENTS.md gets the same rule and the local command.
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.
This adds a pull request check that fails a change that takes a docs URL away without a redirect, or that adds a malformed redirect. Draft: don't merge before smallstep/smallstep.com#1303 is in production. Until then, a redirect entry does nothing.
Why
redirects.jsand went live only with a site deploy, so authors forgot them.manifest.jsonsince 2023./docs/tutorials/mutual-tls-aws(Zero vale errors #493) returned 404 for about 10 months, and four Wi-Fi and MDM guides (Add Protect section: Wireless, Wired, and SSH for GitHub use-case guides #529) for about 4.5 months.redirectsarray inmanifest.jsonas 308s. This check makes sure changes add to it.What changed
"redirects": []inmanifest.json..github/scripts/check-redirects.mjscompares the pull request's merge commit with its base. It uses only git and Node built-ins.source) still works after. Pages under/docs/step-cli/reference/are exempt, because the site sends a dead reference URL to its nearest parent page.sourceanddestination, written as the site matches them, and the destination is a page. No URL is both a page and a source, and no source appears twice.check-redirects.ymlruns on every pull request:editedas well, so a change of base branch runs it again;check-redirects-tests.ymlruns the script's tests when the script or these workflows change.CONTRIBUTING.mdgets a section, "Removing, renaming, or moving a page".AGENTS.mdgets the rule and the local command.What changes for authors
step-ca/templateswould mean updating 25 links in 9 files.node .github/scripts/check-redirects.mjs. Add--base upstream/mainiforiginis a fork.Verification
node --test '.github/scripts/**/*.test.mjs'passes 104 tests. Each rule's test was committed before its implementation./docs/tutorials/mutual-tls-aws.step-cipush 5184bd8 removed tenbeta/careference pages. It fails only for the hand-written link atcertificate-manager/kubernetes-tls/kubernetes-step-issuer.mdx:31.actionlintis clean. Vale wasn't run locally; Lint Prose decides on this pull request.Existing warnings
certificate-manager/kubernetes-tls/kubernetes-step-issuer.mdx:32links to/docs/step-cli/reference/beta/ca/provisioner/add, whichstep-ciremoved in 2023.step-ca/certificate-authority-server-production.mdx:837links to/docs/cli/crypto/jwt/verify.tutorials/protect-wired-networks.mdx:30has a relative JSX link. The site renders JSX as written, so the browser resolves it to/docs/tutorials/protect-wired-networks/protect-wireless-networks.mdx, which works only through an entry in smallstep.com'sredirects.js.Order
check-redirectsto the required checks on main.