Repository navigation
Add automated check to catch broken internal links #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
madolson
merged 11 commits into
valkey-io:main
from
danielfrankcom:check-internal-links
Oct 30, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
31d2ce7
Move the site build into a reusable action
danielfrankcom 1402181
Check internal links on pull requests
danielfrankcom a0bbe0c
Move the link checks into a reusable action
danielfrankcom 504c0f6
Report broken internal links on deploys
danielfrankcom 9254bba
Merge upstream/main
danielfrankcom c9df529
Merge upstream/main
danielfrankcom a03d4b8
Compare unconverted doc links by page and link
danielfrankcom ef49efe
Merge upstream/main
danielfrankcom cca326c
Group deploy checks by blocking
danielfrankcom 9e18804
Empty commit - trigger workflow after upstream fix
danielfrankcom 28e4807
Apply batched suggestions from code review
madolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Build the website | ||
| description: > | ||
| Builds a checkout of this repository into <path>/public, with its topics and | ||
| commands from valkey-doc and the command metadata from valkey and the modules, checked out | ||
| next to it in the workspace. | ||
|
|
||
| inputs: | ||
| path: | ||
| description: The website checkout to build, relative to the workspace (e.g. website). | ||
| required: true | ||
| checkout-content: | ||
| description: Check out the content repositories. Set to false if an earlier build in the job already did. | ||
| default: 'true' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Checkout valkey | ||
| if: inputs.checkout-content == 'true' | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| repository: valkey-io/valkey | ||
| path: valkey | ||
|
|
||
| - name: Checkout valkey-bloom | ||
| if: inputs.checkout-content == 'true' | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| repository: valkey-io/valkey-bloom | ||
| path: valkey-bloom | ||
|
|
||
| - name: Checkout valkey-doc | ||
| if: inputs.checkout-content == 'true' | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| repository: valkey-io/valkey-doc | ||
| path: valkey-doc | ||
|
|
||
| - name: Checkout valkey-json | ||
| if: inputs.checkout-content == 'true' | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| repository: valkey-io/valkey-json | ||
| path: valkey-json | ||
|
|
||
| - name: Checkout valkey-search | ||
| if: inputs.checkout-content == 'true' | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| repository: valkey-io/valkey-search | ||
| path: valkey-search | ||
|
|
||
| - name: Init commands and topics | ||
| shell: bash | ||
| working-directory: ${{ inputs.path }} | ||
| run: | | ||
| ./build/init-topics.sh ../valkey-doc/topics | ||
| ./build/init-commands.sh ../valkey-doc/commands \ | ||
| ../valkey/src/commands ../valkey-bloom/src/commands \ | ||
| ../valkey-json/src/commands ../valkey-search/src/commands | ||
|
|
||
| - name: Build only | ||
| uses: shalzz/zola-deploy-action@1be083648a1db2853ce4970e381740c0e2fd06de # v0.23.6 | ||
| env: | ||
| BUILD_DIR: ${{ inputs.path }} | ||
| BUILD_ONLY: true | ||
| BUILD_THEMES: false |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Check the website's links | ||
| description: > | ||
| Checks a built site (<path>/public) for links to missing pages or #anchors. If base-path is | ||
| provided, only surfaces issues that don't appear in both. | ||
|
|
||
| inputs: | ||
| path: | ||
| description: The website to check the build for, relative to the workspace (e.g. website). | ||
| required: true | ||
| base-path: | ||
| description: A checkout of the base commit to compare with. If it has no public directory, every broken link is listed. | ||
| default: '' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install lychee | ||
| shell: bash | ||
| env: | ||
| LYCHEE_VERSION: v0.24.2 | ||
| LYCHEE_SHA256: 1f4e0ef7f6554a6ed33dd7ac144fb2e1bbed98598e7af973042fc5cd43951c9a | ||
| run: | | ||
| curl -sSfL -o "$RUNNER_TEMP/lychee.tar.gz" \ | ||
| "https://github.com/lycheeverse/lychee/releases/download/lychee-${LYCHEE_VERSION}/lychee-x86_64-unknown-linux-gnu.tar.gz" | ||
| echo "$LYCHEE_SHA256 $RUNNER_TEMP/lychee.tar.gz" | sha256sum -c - | ||
| tar -xzf "$RUNNER_TEMP/lychee.tar.gz" -C "$RUNNER_TEMP" --strip-components=1 lychee-x86_64-unknown-linux-gnu/lychee | ||
| echo "$RUNNER_TEMP" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Check links | ||
| shell: bash | ||
| env: | ||
| CHECKOUT: ${{ inputs.path }} | ||
| BASE_CHECKOUT: ${{ inputs.base-path }} | ||
| run: | | ||
| status=0 | ||
| for check in broken-links unconverted-doc-links; do | ||
| echo "build/$check.sh:" | ||
| before=- | ||
| if [ -n "$BASE_CHECKOUT" ]; then | ||
| before=$RUNNER_TEMP/$check-before.txt | ||
| if [ -d "$BASE_CHECKOUT/public" ]; then "$CHECKOUT/build/$check.sh" "$BASE_CHECKOUT/public" > "$before"; fi | ||
| fi | ||
| "$CHECKOUT/build/$check.sh" "$CHECKOUT/public" > "$RUNNER_TEMP/$check.txt" | ||
| "$CHECKOUT/build/compare-link-failures.sh" "$before" "$RUNNER_TEMP/$check.txt" || status=1 | ||
| done | ||
| exit "$status" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Builds the site before and after the PR. Fails if the PR breaks internal links. | ||
| # Links already broken before the PR are listed but don't fail the check. | ||
|
|
||
| name: Link check | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: ["main"] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: link-check-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| internal-links: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| path: website | ||
| fetch-depth: 0 # for the base commit | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| - name: Check out the base commit | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: git -C website worktree add --detach ../base "$BASE_SHA" | ||
|
|
||
| # Each side uses its own build-site, so changes to the build itself are checked too. | ||
| # If the base doesn't build or has no build-site, the checks list every broken link | ||
| # instead. | ||
| - name: Build this PR | ||
| id: head | ||
| uses: ./website/.github/actions/build-site | ||
| with: | ||
| path: website | ||
|
|
||
| - name: Build the base | ||
| id: base | ||
| if: hashFiles('base/.github/actions/build-site/action.yml') != '' | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| continue-on-error: true | ||
| uses: ./base/.github/actions/build-site | ||
| with: | ||
| path: base | ||
| checkout-content: false | ||
|
|
||
| # A failed build can leave part of a site, which could hide links the PR breaks. | ||
| - name: Discard a failed base build | ||
| if: steps.base.outcome == 'failure' | ||
| run: rm -rf base/public | ||
|
|
||
| - name: Check links | ||
| uses: ./website/.github/actions/check-links | ||
| with: | ||
| path: website | ||
| base-path: base | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/usr/bin/env bash | ||
| # Lists links in a built site to missing pages or #anchors. | ||
| # | ||
| # build/broken-links.sh public | ||
| set -euo pipefail | ||
| site=$(cd "${1:?usage: broken-links.sh <built site>}" && pwd -P) | ||
| report=$(mktemp) | ||
|
|
||
| status=0 | ||
| # --offline skips links written as https://valkey.io/..., so point them at the build. | ||
| lychee --offline --no-progress --format json --output "$report" --config "$(dirname "$0")/lychee.toml" \ | ||
| --root-dir "$site" --remap "^https://valkey\.io/([^?#]*)[^#]*(#.*)?$ file://$site/\$1\$2" \ | ||
| "$site" > /dev/null || status=$? | ||
| case $status in | ||
| 0 | 2) ;; # 2 means lychee found broken links | ||
| *) echo "lychee itself failed (exit code $status)" >&2; exit 1 ;; | ||
| esac | ||
|
|
||
| jq -r --arg root "$site" '.error_map | to_entries[] | .key as $page | .value[] | ||
| | (.url | ltrimstr("file://" + $root)) as $link | ||
| | ($page | ltrimstr($root) | rtrimstr("index.html")) as $on | ||
| | (if (.status.text | startswith("Cannot find fragment")) then "but that page has no #\($link | split("#") | last) anchor" | ||
| elif (.status.text | startswith("File not found")) then "but no such page exists" | ||
| else .status.text end) as $problem | ||
| | [$link, "\($on) links to \($link), \($problem)"] | @tsv' "$report" \ | ||
| | sort -u |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env bash | ||
| # Prints failures from broken-links.sh or unconverted-doc-links.sh. | ||
| # | ||
| # build/compare-link-failures.sh <before> <after> | ||
| # Fails if a link in <after> isn't in <before>. If <before> doesn't exist (the base | ||
| # didn't build), lists everything as below. | ||
| # build/compare-link-failures.sh - <failures> | ||
| # Fails if there are any failures. | ||
| # | ||
| # Compares the first field of each failure. broken-links.sh puts only the link there, so a new | ||
| # page that inherits a dead footer link doesn't fail. | ||
| set -euo pipefail | ||
| before=${1:?usage: compare-link-failures.sh <before|-> <after>} after=${2:?} | ||
|
|
||
| if [ "$before" != - ] && [ ! -e "$before" ]; then | ||
| echo "The base commit didn't build, so every broken link is listed." | ||
| before=- | ||
| fi | ||
|
|
||
| if [ "$before" = - ]; then | ||
| if [ ! -s "$after" ]; then | ||
| echo "No broken links." | ||
| exit 0 | ||
| fi | ||
| echo "Broken links ($(wc -l < "$after" | tr -d ' ')):" | ||
| cut -f2 "$after" | sed 's/^/::error::/' | ||
| exit 1 | ||
| fi | ||
|
|
||
| new_links=$(comm -13 <(cut -f1 "$before" | sort -u) <(cut -f1 "$after" | sort -u)) | ||
|
|
||
| # Each failure is "link<TAB>message". Group the messages by whether their link is new. | ||
| new=() already=() | ||
| while IFS=$'\t' read -r link message; do | ||
| if grep -qxF -- "$link" <<< "$new_links"; then | ||
| new+=("$message") | ||
| else | ||
| already+=("$message") | ||
| fi | ||
| done < "$after" | ||
|
|
||
| if [ ${#new[@]} -gt 0 ]; then | ||
| echo "Broken by this change (${#new[@]}):" | ||
| printf '::error::%s\n' "${new[@]}" | ||
| else | ||
| echo "This change doesn't break any links." | ||
| fi | ||
| if [ ${#already[@]} -gt 0 ]; then | ||
| echo "Already broken before this change (${#already[@]}):" | ||
| printf ' %s\n' "${already[@]}" | ||
| fi | ||
| if [ ${#new[@]} -gt 0 ]; then | ||
| exit 1 | ||
| fi |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Used by build/broken-links.sh. | ||
|
|
||
| # Not "full", because lychee's #:~:text= fragment checking is new and was unreliable in testing. | ||
| include_fragments = "anchor-only" | ||
|
|
||
| # Zola writes /topics/foo/ as topics/foo/index.html. | ||
| index_files = ["index.html"] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.