Skip to content

Commit 953692f

Browse files
check-links: report absolute self-links only with --check-self-links, so next build fails on dead links alone
Amp-Thread-ID: https://ampcode.com/threads/T-01a08a01-44c1-775b-84d0-d67ff9501905 Co-authored-by: Amp <amp@ampcode.com>
1 parent aba7bc5 commit 953692f

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

.github/workflows/check-links.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Record broken links already present on the base branch
4747
# Exit 1 means findings, which is expected here
4848
run: |
49-
node dev/check-links.mjs --check-anchors --format json \
49+
node dev/check-links.mjs --check-anchors --check-self-links --format json \
5050
--root "$RUNNER_TEMP/base" > "$RUNNER_TEMP/base-links.json" \
5151
|| [ $? -eq 1 ]
5252
@@ -56,7 +56,7 @@ jobs:
5656
# File links in the report open the file on the PR branch
5757
LINK_BASE: ${{ github.event.pull_request.head.repo.html_url }}/blob/${{ github.event.pull_request.head.ref }}
5858
run: |
59-
if node dev/check-links.mjs --check-anchors --check-external --format markdown \
59+
if node dev/check-links.mjs --check-anchors --check-self-links --check-external --format markdown \
6060
--baseline "$RUNNER_TEMP/base-links.json" \
6161
--diff "$RUNNER_TEMP/changes.diff" \
6262
--review "$RUNNER_TEMP/review.json" \

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- **Build**: `npm run build`
77
- **Dev**: `npm run dev`
88
- **Lint**: `npm run lint`
9-
- **Check links**: `npm run check-links -- --check-anchors` (CI comments on PRs that break links; see `dev/check-links.mjs`). When moving a page or renaming a heading, update every link to it; a redirect in `src/data/redirects.ts` does not satisfy the check. Link to this site with relative paths (`/admin/config/site-config`), never `https://sourcegraph.com/docs/…` or `https://docs.sourcegraph.com/…`. To also probe the external links you added: `npm run check-links -- --check-anchors --check-external --diff <(git diff -U0 origin/main)`
9+
- **Check links**: `npm run check-links -- --check-anchors --check-self-links` (CI comments on PRs that break links; see `dev/check-links.mjs`; `next build` runs it without flags, so only dead page links fail a deploy). When moving a page or renaming a heading, update every link to it; a redirect in `src/data/redirects.ts` does not satisfy the check. Link to this site with relative paths (`/admin/config/site-config`), never `https://sourcegraph.com/docs/…` or `https://docs.sourcegraph.com/…`. To also probe the external links you added: `npm run check-links -- --check-anchors --check-self-links --check-external --diff <(git diff -U0 origin/main)`
1010
- **Prove changed links resolve on a deploy**: `node dev/verify-links-live.mjs --site <vercel-preview-url>` prints a Markdown table for the PR description
1111

1212
## AI Chat Integration

dev/check-links.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
* - Links whose case differs from the real path (work on macOS, 404 on Linux)
1212
* - Missing anchor/heading references
1313
* - Invalid file paths
14-
* - Absolute links to this site (https://sourcegraph.com/docs/..., the legacy
15-
* https://docs.sourcegraph.com/... host, http://, //, www.), which should be
16-
* relative links; the finding proposes one, following src/data/redirects.ts
14+
* - With --check-self-links, absolute links to this site (https://sourcegraph.com/docs/...,
15+
* the legacy https://docs.sourcegraph.com/... host, http://, //, www.), which
16+
* should be relative links; the finding proposes one, following src/data/redirects.ts
1717
* - With --check-external, external links on added lines that return 404 or 410
18-
*
18+
*
19+
* next.config.js runs this with no flags on every build, so only dead page links
20+
* can fail a deploy; the flags below are for the pull request workflow.
21+
*
1922
* Usage: node dev/check-links.mjs [options]
2023
* --check-anchors Also validate #anchors against headings
24+
* --check-self-links Also report absolute links to this site
2125
* --root <dir> Repository to check (default: this repository)
2226
* --format <name> Output as text (default), json, or markdown
2327
* --baseline <file> Only report findings absent from this JSON file
@@ -49,6 +53,7 @@ const __dirname = path.dirname(__filename);
4953
// Parse CLI flags
5054
const args = process.argv.slice(2);
5155
const CHECK_ANCHORS = args.includes('--check-anchors');
56+
const CHECK_SELF_LINKS = args.includes('--check-self-links');
5257
const ROOT_DIR = path.resolve(flagValue('--root') ?? path.dirname(__dirname));
5358
const FORMAT = flagValue('--format') ?? 'text';
5459
const BASELINE_FILE = flagValue('--baseline');
@@ -326,7 +331,7 @@ function validateLink(link, currentFile, maps) {
326331
const { url } = link;
327332

328333
if (isSelfLink(url)) {
329-
return validateSelfLink(url, currentFile, maps);
334+
return CHECK_SELF_LINKS ? validateSelfLink(url, currentFile, maps) : null;
330335
}
331336

332337
// Skip external links, mailto, tel, javascript, etc.

0 commit comments

Comments
 (0)