Skip to content

Commit b3c6525

Browse files
authored
fix: Filter linkchecker output (#2406)
1 parent 1297264 commit b3c6525

File tree

5 files changed

+153
-24
lines changed

5 files changed

+153
-24
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,5 @@ jobs:
8888
- name: yarn install
8989
if: steps.cache.outputs.cache-hit != 'true'
9090
run: yarn install
91-
- name: Install httpserver
92-
run: volta install http-server
93-
- name: Install linkcheck
94-
if: steps.cache.outputs.cache-hit != 'true'
95-
run: |-
96-
wget -nc https://github.com/filiph/linkcheck/releases/download/v2.0.12/linkcheck-linux-x64.exe -O ./linkcheck
97-
chmod +x ./linkcheck
98-
- name: Build
99-
run: yarn build
100-
- name: Run linkcheck (search for "HTTP 404" in logs to get to errors)
101-
run: |-
102-
http-server public/ > /dev/null &
103-
printf "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'
104-
105-
# exitcode=1 -- only warnings (about broken anchors)
106-
# exitcode=2 -- hard 404s
107-
# We only fail the build if there are hard 404s
108-
./linkcheck http://localhost:8080 || [ $? -eq 1 ]
91+
- name: yarn linkcheck
92+
run: yarn linkcheck

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ static/_platforms/
7777

7878
# generated nginx file
7979
nginx.out.conf
80+
81+
# linkchecker binary
82+
linkcheck

bin/linkchecker

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
set -e
3+
set -o pipefail
4+
5+
LINKCHECK_VERSION=2.0.12
6+
7+
# This linkchecker written in Dart is the fastest we've found and finds the
8+
# most links. It is still very slow, requires a separate HTTP server, and is
9+
# barely configurable wrt output verbosity. Hence this script exists.
10+
#
11+
# Considering lack of performant, correct alternatives we *assume* that
12+
# building our own would be hard.
13+
14+
if [ "$(uname)" = "Darwin" ]; then
15+
url="https://github.com/filiph/linkcheck/releases/download/v$LINKCHECK_VERSION/linkcheck-mac-x64"
16+
else
17+
url="https://github.com/filiph/linkcheck/releases/download/v$LINKCHECK_VERSION/linkcheck-linux-x64.exe"
18+
fi
19+
20+
if [ ! -f ./linkcheck ]; then
21+
echo ">>> Downloading linkcheck"
22+
wget -nc "$url" -O ./linkcheck
23+
chmod +x ./linkcheck
24+
fi
25+
26+
echo ">>> Building docs"
27+
yarn build
28+
29+
echo ">>> Starting HTTP server"
30+
yarn http-server public/ > /dev/null &
31+
httpserver_pid=$!
32+
trap "kill -9 $httpserver_pid" SIGINT SIGTERM EXIT
33+
34+
echo ">>> Waiting for server to be up"
35+
timeout 60 bash -c 'until $(curl -Isf -o /dev/null "http://localhost:8080"); do printf '.'; sleep 0.5; done'
36+
37+
# exitcode=1 -- only warnings (about broken anchors)
38+
# exitcode=2 -- hard 404s
39+
# We only fail the build if there are hard 404s
40+
echo ">>> Checking some links (started at $(date))"
41+
echo " This step takes 5-10 minutes and does not produce intermediate output."
42+
echo " If your fans are spinning it's working."
43+
(./linkcheck http://localhost:8080 || [ $? -eq 1 ]) | \
44+
45+
# Post-process the output and remove all anchor warnings
46+
grep -v "(HTTP 200 but missing anchor)" | \
47+
48+
# Clean up output some more, launch in subshell because of namespace
49+
# pollution (and because I want to keep the bash-isms to a minimum)
50+
(
51+
prev_line=""
52+
while IFS= read line; do
53+
# XXX: Bashism
54+
if [ -z "$line" ] && [[ "$prev_line" = http://localhost:8080/* ]]; then
55+
# We are in a section for which we report nothing (because we grepped
56+
# away anchor warnings):
57+
#
58+
# http://... <-- prev_line
59+
# <-- line
60+
# http://...
61+
62+
true
63+
else
64+
echo "$prev_line"
65+
fi
66+
67+
prev_line="$line"
68+
done
69+
70+
# Since the loop always outputs the prev_line, we need to fix the off-by-one error here
71+
echo "$prev_line"
72+
) | \
73+
74+
# Remove repeated blank lines
75+
cat -s
76+
77+
kill -9 $httpserver_pid

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"prettier:fix:all": "prettier --write \"./{src,plugins}/**/*.{md,mdx,js,jsx}\"",
9191
"start": "yarn run develop",
9292
"format": "prettier --write \"src/**/*.js\"",
93-
"test": "jest"
93+
"test": "jest",
94+
"linkcheck": "bin/linkchecker"
9495
},
9596
"devDependencies": {
9697
"@testing-library/jest-dom": "^5.11.4",
@@ -106,6 +107,7 @@
106107
"eslint-plugin-react": "^7.20.6",
107108
"est": "^0.2.1-alpha",
108109
"gh-pages": "^2.2.0",
110+
"http-server": "^0.12.3",
109111
"identity-obj-proxy": "^3.0.0",
110112
"jest": "^26.4.2",
111113
"jest-dom": "^4.0.0",

yarn.lock

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,6 +4102,11 @@ base@^0.11.1:
41024102
mixin-deep "^1.2.0"
41034103
pascalcase "^0.1.1"
41044104

4105+
basic-auth@^1.0.3:
4106+
version "1.1.0"
4107+
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-1.1.0.tgz#45221ee429f7ee1e5035be3f51533f1cdfd29884"
4108+
integrity sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ=
4109+
41054110
41064111
version "0.6.1"
41074112
resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16"
@@ -5210,7 +5215,7 @@ colorette@^1.2.1:
52105215
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
52115216
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
52125217

5213-
colors@^1.1.2:
5218+
colors@^1.1.2, colors@^1.4.0:
52145219
version "1.4.0"
52155220
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
52165221
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
@@ -5526,6 +5531,11 @@ cors@^2.8.5:
55265531
object-assign "^4"
55275532
vary "^1"
55285533

5534+
corser@^2.0.1:
5535+
version "2.0.1"
5536+
resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
5537+
integrity sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c=
5538+
55295539
cosmiconfig@^5.0.0:
55305540
version "5.2.1"
55315541
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
@@ -6601,6 +6611,16 @@ ecc-jsbn@~0.1.1:
66016611
jsbn "~0.1.0"
66026612
safer-buffer "^2.1.0"
66036613

6614+
ecstatic@^3.3.2:
6615+
version "3.3.2"
6616+
resolved "https://registry.yarnpkg.com/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48"
6617+
integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==
6618+
dependencies:
6619+
he "^1.1.1"
6620+
mime "^1.6.0"
6621+
minimist "^1.1.0"
6622+
url-join "^2.0.5"
6623+
66046624
66056625
version "1.1.1"
66066626
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
@@ -9542,6 +9562,11 @@ hastscript@^5.0.0:
95429562
property-information "^5.0.0"
95439563
space-separated-tokens "^1.0.0"
95449564

9565+
he@^1.1.1:
9566+
version "1.2.0"
9567+
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
9568+
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
9569+
95459570
header-case@^1.0.0:
95469571
version "1.0.1"
95479572
resolved "https://registry.yarnpkg.com/header-case/-/header-case-1.0.1.tgz#9535973197c144b09613cd65d317ef19963bd02d"
@@ -9767,7 +9792,7 @@ [email protected]:
97679792
lodash "^4.17.11"
97689793
micromatch "^3.1.10"
97699794

9770-
http-proxy@^1.17.0, http-proxy@^1.18.1:
9795+
http-proxy@^1.17.0, http-proxy@^1.18.0, http-proxy@^1.18.1:
97719796
version "1.18.1"
97729797
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
97739798
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
@@ -9776,6 +9801,22 @@ http-proxy@^1.17.0, http-proxy@^1.18.1:
97769801
follow-redirects "^1.0.0"
97779802
requires-port "^1.0.0"
97789803

9804+
http-server@^0.12.3:
9805+
version "0.12.3"
9806+
resolved "https://registry.yarnpkg.com/http-server/-/http-server-0.12.3.tgz#ba0471d0ecc425886616cb35c4faf279140a0d37"
9807+
integrity sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA==
9808+
dependencies:
9809+
basic-auth "^1.0.3"
9810+
colors "^1.4.0"
9811+
corser "^2.0.1"
9812+
ecstatic "^3.3.2"
9813+
http-proxy "^1.18.0"
9814+
minimist "^1.2.5"
9815+
opener "^1.5.1"
9816+
portfinder "^1.0.25"
9817+
secure-compare "3.0.1"
9818+
union "~0.5.0"
9819+
97799820
http-signature@~1.2.0:
97809821
version "1.2.0"
97819822
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
@@ -12389,7 +12430,7 @@ mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.19, mime-types@~2.1.24:
1238912430
dependencies:
1239012431
mime-db "1.44.0"
1239112432

12392-
[email protected], mime@^1.3.4:
12433+
[email protected], mime@^1.3.4, mime@^1.6.0:
1239312434
version "1.6.0"
1239412435
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
1239512436
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
@@ -13154,6 +13195,11 @@ open@^6.4.0:
1315413195
dependencies:
1315513196
is-wsl "^1.1.0"
1315613197

13198+
opener@^1.5.1:
13199+
version "1.5.2"
13200+
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598"
13201+
integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==
13202+
1315713203
opentracing@^0.14.4:
1315813204
version "0.14.4"
1315913205
resolved "https://registry.yarnpkg.com/opentracing/-/opentracing-0.14.4.tgz#a113408ea740da3a90fde5b3b0011a375c2e4268"
@@ -13903,7 +13949,7 @@ pnp-webpack-plugin@^1.6.4:
1390313949
dependencies:
1390413950
ts-pnp "^1.1.6"
1390513951

13906-
portfinder@^1.0.26:
13952+
portfinder@^1.0.25, portfinder@^1.0.26:
1390713953
version "1.0.28"
1390813954
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.28.tgz#67c4622852bd5374dd1dd900f779f53462fac778"
1390913955
integrity sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA==
@@ -14561,7 +14607,7 @@ [email protected]:
1456114607
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
1456214608
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
1456314609

14564-
qs@^6.5.2:
14610+
qs@^6.4.0, qs@^6.5.2:
1456514611
version "6.9.4"
1456614612
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
1456714613
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==
@@ -15887,6 +15933,11 @@ section-matter@^1.0.0:
1588715933
extend-shallow "^2.0.1"
1588815934
kind-of "^6.0.0"
1588915935

15936+
15937+
version "3.0.1"
15938+
resolved "https://registry.yarnpkg.com/secure-compare/-/secure-compare-3.0.1.tgz#f1a0329b308b221fae37b9974f3d578d0ca999e3"
15939+
integrity sha1-8aAymzCLIh+uN7mXTz1XjQypmeM=
15940+
1589015941
seek-bzip@^1.0.5:
1589115942
version "1.0.6"
1589215943
resolved "https://registry.yarnpkg.com/seek-bzip/-/seek-bzip-1.0.6.tgz#35c4171f55a680916b52a07859ecf3b5857f21c4"
@@ -17794,6 +17845,13 @@ union-value@^1.0.0:
1779417845
is-extendable "^0.1.1"
1779517846
set-value "^2.0.1"
1779617847

17848+
union@~0.5.0:
17849+
version "0.5.0"
17850+
resolved "https://registry.yarnpkg.com/union/-/union-0.5.0.tgz#b2c11be84f60538537b846edb9ba266ba0090075"
17851+
integrity sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==
17852+
dependencies:
17853+
qs "^6.4.0"
17854+
1779717855
uniq@^1.0.1:
1779817856
version "1.0.1"
1779917857
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
@@ -18060,6 +18118,11 @@ urix@^0.1.0:
1806018118
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
1806118119
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
1806218120

18121+
url-join@^2.0.5:
18122+
version "2.0.5"
18123+
resolved "https://registry.yarnpkg.com/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
18124+
integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=
18125+
1806318126
url-loader@^1.1.2:
1806418127
version "1.1.2"
1806518128
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-1.1.2.tgz#b971d191b83af693c5e3fea4064be9e1f2d7f8d8"

0 commit comments

Comments
 (0)