Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,13 @@ jobs:
fi

- name: Suggest fixes as review comments
# One suggested change per added line with a fix. Suggestions already on
# the PR (same file, line, and text) are not posted again.
if: steps.check.outputs.broken == 'true' && github.event.pull_request.head.repo.full_name == github.repository
# One suggested change per finding with a fix, kept in sync with the
# findings; see dev/sync-review-comments.sh
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/comments" --paginate \
--jq '.[] | {path, line, body}' | jq -s . > "$RUNNER_TEMP/posted.json"
jq --slurpfile posted "$RUNNER_TEMP/posted.json" \
'.comments |= map(select(. as $comment | $posted[0] | index({path: $comment.path, line: $comment.line, body: $comment.body}) | not))' \
"$RUNNER_TEMP/review.json" > "$RUNNER_TEMP/review-new.json"

if [ "$(jq '.comments | length' "$RUNNER_TEMP/review-new.json")" -gt 0 ]; then
gh api --method POST "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews" \
--input "$RUNNER_TEMP/review-new.json" > /dev/null \
|| echo "::warning::Could not post the suggested fixes; they are in the report above"
fi
run: dev/sync-review-comments.sh '<!-- check-links-finding:' "$RUNNER_TEMP/review.json"

- name: Fail when this PR introduces broken links
if: steps.check.outputs.broken == 'true'
Expand Down
111 changes: 111 additions & 0 deletions .github/workflows/check-redirects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Check redirects

# Reports redirects in src/data/redirects.ts that this PR breaks, compared with
# the merge base: destinations that no longer exist, #fragments whose heading
# was renamed, and new redirects that shadow an existing page. Pre-existing
# broken redirects on the base branch are ignored.

on:
pull_request:

# A new push supersedes the run for the previous one
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
check-redirects:
name: Broken redirects introduced by this PR
runs-on: ubuntu-latest
steps:
- name: Check out pull request head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Install github-slugger, the only dependency of dev/check-redirects.mjs
# Into a scratch prefix, not the repo: `npm install <pkg>` next to
# package.json would install every dependency of the site
run: |
npm install --prefix "$RUNNER_TEMP/deps" --no-package-lock --no-audit --no-fund \
"github-slugger@$(node -p 'require("./package.json").dependencies["github-slugger"]')"
ln -s "$RUNNER_TEMP/deps/node_modules" node_modules

- name: Check out merge base
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
merge_base=$(git merge-base "$BASE_SHA" HEAD)
git worktree add "$RUNNER_TEMP/base" "$merge_base"
git diff -U0 "$merge_base" HEAD -- src/data/redirects.ts > "$RUNNER_TEMP/changes.diff"

- name: Record broken redirects already present on the base branch
# Exit 1 means findings, which is expected here
run: |
node dev/check-redirects.mjs --format json \
--root "$RUNNER_TEMP/base" > "$RUNNER_TEMP/base-redirects.json" \
|| [ $? -eq 1 ]

- name: Find redirects broken by this PR
id: check
env:
# Line links in the report open redirects.ts on the PR branch
LINK_BASE: ${{ github.event.pull_request.head.repo.html_url }}/blob/${{ github.event.pull_request.head.ref }}
run: |
if node dev/check-redirects.mjs --format markdown \
--baseline "$RUNNER_TEMP/base-redirects.json" \
--diff "$RUNNER_TEMP/changes.diff" \
--review "$RUNNER_TEMP/review.json" \
--link-base "$LINK_BASE" > "$RUNNER_TEMP/report.md"; then
echo "broken=false" >> "$GITHUB_OUTPUT"
else
echo "broken=true" >> "$GITHUB_OUTPUT"
fi
cat "$RUNNER_TEMP/report.md"

- name: Comment on the pull request
# Fork PRs get a read-only token; the report is still in the job log
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BROKEN: ${{ steps.check.outputs.broken }}
run: |
marker='<!-- check-redirects-report -->'
existing_comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
--paginate --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1)

# Comment only when there is something to report, or an earlier report to resolve
if [ "$BROKEN" = true ]; then
{ echo "$marker"; cat "$RUNNER_TEMP/report.md"; } > "$RUNNER_TEMP/comment.md"
elif [ -n "$existing_comment" ]; then
printf '%s\n### ✅ The redirects an earlier revision of this PR broke are fixed\n' \
"$marker" > "$RUNNER_TEMP/comment.md"
else
exit 0
fi

if [ -n "$existing_comment" ]; then
gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$existing_comment" \
--field body=@"$RUNNER_TEMP/comment.md"
else
gh pr comment "$PR_NUMBER" --body-file "$RUNNER_TEMP/comment.md"
fi

- name: Suggest fixes as review comments
# One suggested change per fixable entry this PR added, kept in sync
# with the findings; see dev/sync-review-comments.sh
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: dev/sync-review-comments.sh '<!-- check-redirects-finding:' "$RUNNER_TEMP/review.json"

- name: Fail when this PR breaks redirects
if: steps.check.outputs.broken == 'true'
run: exit 1
52 changes: 52 additions & 0 deletions .github/workflows/vercel-build-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Vercel build report

# Vercel only shows build logs to members of its team. When a PR's Vercel
# build fails, this comments the end of the build log on the PR; when a later
# revision builds, the comment is updated to say so.
#
# GitHub only delivers repository_dispatch to the workflow file on the default
# branch, so workflow_dispatch takes the same payload fields as inputs for
# testing before merge and for re-running on a PR by hand:
# gh workflow run vercel-build-report.yml --ref <branch> \
# -f id=dpl_... -f state=error -f sha=<pr head sha>
on:
repository_dispatch:
types: [vercel.deployment.error, vercel.deployment.success]
workflow_dispatch:
inputs:
id:
description: Vercel deployment ID (client_payload.id)
required: true
state:
description: Deployment state (client_payload.state.type)
required: true
type: choice
options: [error, success]
sha:
description: Full commit SHA of the PR head (client_payload.git.sha)
required: true

permissions:
contents: read
pull-requests: write

jobs:
report:
if: github.event.client_payload.environment != 'production'
runs-on: ubuntu-latest
steps:
- name: Check out dev/report-vercel-build.mjs
uses: actions/checkout@v4
with:
sparse-checkout: dev/report-vercel-build.mjs
sparse-checkout-cone-mode: false

- name: Comment on the pull request
env:
GH_TOKEN: ${{ github.token }}
DEPLOYMENT_ID: ${{ github.event.client_payload.id || inputs.id }}
DEPLOYMENT_STATE: ${{ github.event.client_payload.state.type || inputs.state }}
COMMIT_SHA: ${{ github.event.client_payload.git.sha || inputs.sha }}
# Scoped to the sourcegraph-docs project, so it needs no team ID
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: node dev/report-vercel-build.mjs
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
- **Lint**: `npm run lint`
- **Checks**: `npm run check` runs every `dev/check-*.mjs` (links, filenames, images); `npm run build` runs them first, so any finding fails a deploy
- **Check links**: `npm run check -- links --check-anchors --check-self-links` (CI comments on PRs that break links; see `dev/check-links.mjs`; the 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)`
- **Check redirects**: `node dev/check-redirects.mjs` reports broken entries in `src/data/redirects.ts` (CI comments on PRs that break redirects; see the script header for what it checks). Not part of `npm run check`: main has hundreds of pre-existing findings, and CI only reports the ones a PR adds
- **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
- **Vercel build failures**: Vercel shows build logs only to its team members, so `.github/workflows/vercel-build-report.yml` comments the log tail on the PR (see `dev/report-vercel-build.mjs`). It reads Vercel with the `VERCEL_TOKEN` repo secret, a token scoped to the `sourcegraph-docs` project that expires 2026-12-10; mint a new one with `POST /v3/user/tokens?teamId=<team>` and `projectId` in the body

## AI Chat Integration

Expand Down
2 changes: 2 additions & 0 deletions cspell-allow-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ appendonly
appengine
appgw
ARGF
argjson # jq option
atoburl
atoi
attnum
Expand Down Expand Up @@ -545,6 +546,7 @@ toolcall
topk
topsecretorg
topsecretproject
tostring # jq builtin
transactionally
transformchanges
transformchangesgroup
Expand Down
Loading
Loading