-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Filter linkchecker output (#2406)
- Loading branch information
Showing
5 changed files
with
153 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -77,3 +77,6 @@ static/_platforms/ | |
|
||
# generated nginx file | ||
nginx.out.conf | ||
|
||
# linkchecker binary | ||
linkcheck |
This file contains 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,77 @@ | ||
#!/bin/bash | ||
set -e | ||
set -o pipefail | ||
|
||
LINKCHECK_VERSION=2.0.12 | ||
|
||
# This linkchecker written in Dart is the fastest we've found and finds the | ||
# most links. It is still very slow, requires a separate HTTP server, and is | ||
# barely configurable wrt output verbosity. Hence this script exists. | ||
# | ||
# Considering lack of performant, correct alternatives we *assume* that | ||
# building our own would be hard. | ||
|
||
if [ "$(uname)" = "Darwin" ]; then | ||
url="https://github.com/filiph/linkcheck/releases/download/v$LINKCHECK_VERSION/linkcheck-mac-x64" | ||
else | ||
url="https://github.com/filiph/linkcheck/releases/download/v$LINKCHECK_VERSION/linkcheck-linux-x64.exe" | ||
fi | ||
|
||
if [ ! -f ./linkcheck ]; then | ||
echo ">>> Downloading linkcheck" | ||
wget -nc "$url" -O ./linkcheck | ||
chmod +x ./linkcheck | ||
fi | ||
|
||
echo ">>> Building docs" | ||
yarn build | ||
|
||
echo ">>> Starting HTTP server" | ||
yarn http-server public/ > /dev/null & | ||
httpserver_pid=$! | ||
trap "kill -9 $httpserver_pid" SIGINT SIGTERM EXIT | ||
|
||
echo ">>> Waiting for server to be up" | ||
timeout 60 bash -c 'until $(curl -Isf -o /dev/null "http://localhost:8080"); do printf '.'; sleep 0.5; done' | ||
|
||
# exitcode=1 -- only warnings (about broken anchors) | ||
# exitcode=2 -- hard 404s | ||
# We only fail the build if there are hard 404s | ||
echo ">>> Checking some links (started at $(date))" | ||
echo " This step takes 5-10 minutes and does not produce intermediate output." | ||
echo " If your fans are spinning it's working." | ||
(./linkcheck http://localhost:8080 || [ $? -eq 1 ]) | \ | ||
|
||
# Post-process the output and remove all anchor warnings | ||
grep -v "(HTTP 200 but missing anchor)" | \ | ||
|
||
# Clean up output some more, launch in subshell because of namespace | ||
# pollution (and because I want to keep the bash-isms to a minimum) | ||
( | ||
prev_line="" | ||
while IFS= read line; do | ||
# XXX: Bashism | ||
if [ -z "$line" ] && [[ "$prev_line" = http://localhost:8080/* ]]; then | ||
# We are in a section for which we report nothing (because we grepped | ||
# away anchor warnings): | ||
# | ||
# http://... <-- prev_line | ||
# <-- line | ||
# http://... | ||
|
||
true | ||
else | ||
echo "$prev_line" | ||
fi | ||
|
||
prev_line="$line" | ||
done | ||
|
||
# Since the loop always outputs the prev_line, we need to fix the off-by-one error here | ||
echo "$prev_line" | ||
) | \ | ||
|
||
# Remove repeated blank lines | ||
cat -s | ||
|
||
kill -9 $httpserver_pid |
This file contains 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 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