Skip to content
Merged
67 changes: 67 additions & 0 deletions .github/actions/build-site/action.yml
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
46 changes: 46 additions & 0 deletions .github/actions/check-links/action.yml
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"
Comment thread
madolson marked this conversation as resolved.
Resolved

- 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"
59 changes: 59 additions & 0 deletions .github/workflows/link-check.yml
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
Comment thread
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') != ''
Comment thread
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
79 changes: 34 additions & 45 deletions .github/workflows/zola-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,19 @@ jobs:
ref: ${{ github.event_name != 'pull_request' && 'main' || '' }}
path: website

- name: Checkout valkey-doc
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: valkey-io/valkey-doc
path: valkey-doc

- name: Checkout valkey
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: valkey-io/valkey
path: valkey

- name: Checkout valkey-bloom
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: valkey-io/valkey-bloom
path: valkey-bloom

- name: Checkout valkey-search
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: valkey-io/valkey-search
path: valkey-search

- name: Checkout valkey-json
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Build
uses: ./website/.github/actions/build-site
with:
repository: valkey-io/valkey-json
path: valkey-json

- name: Init commands and topics
run: |
cd website
./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: website
BUILD_ONLY: true
BUILD_THEMES: false
path: website

- name: Upload artifact
if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
with:
path: ./website/public

validate:
# Deploys wait for these.
blocking-checks:
needs: build
if: github.event_name != 'pull_request'
uses: ./.github/workflows/validate-libraries.yml
Expand All @@ -93,8 +54,36 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: [build, validate]
needs: [build, blocking-checks]
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4

# Deploys don't wait for these. The target of these checks comes from other repositories
# (valkey-doc, valkey, etc.), so blocking would hold back site updates until external fixes could
# be made. The checks here are intended as primarily informational.
non-blocking-checks:
needs: build
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ needs.build.outputs.commit }}

- name: Download the built site
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: github-pages

- name: Unpack the built site
run: mkdir public && tar -xf artifact.tar -C public

- name: Check links
uses: ./.github/actions/check-links
with:
path: .
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ Point your browser at `http://127.0.0.1:1111/commands/` and you should see the f
All files created in this process are ignored by git.
Commit your changes to your local copy of `valkey-io/valkey-doc` for description changes and `valkey-io/valkey` for command JSON changes (if you have any).

### Checking links

Pull requests and deploys check the built site for links to missing pages or `#anchors`, and for valkey-doc links that weren't converted to site URLs.
To run the checks locally (needs [lychee](https://lychee.cli.rs/) and jq), set up the topics and commands as above, then:

```shell
zola build
build/broken-links.sh public
build/unconverted-doc-links.sh public
```

## License

This project is licensed under the BSD-3-Clause License.
26 changes: 26 additions & 0 deletions build/broken-links.sh
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
54 changes: 54 additions & 0 deletions build/compare-link-failures.sh
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
7 changes: 7 additions & 0 deletions build/lychee.toml
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"]
Loading
Loading