Skip to content

Commit 1620c70

Browse files
authored
Script to validate links (#10309)
1 parent 4401fab commit 1620c70

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/check_links.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -euo pipefail
9+
10+
status=0
11+
green='\e[1;32m'; red='\e[1;31m'; cyan='\e[1;36m'; yellow='\e[1;33m'; reset='\e[0m'
12+
last_filepath=
13+
14+
while IFS=: read -r filepath link; do
15+
if [ "$filepath" != "$last_filepath" ]; then
16+
printf '\n%s:\n' "$filepath"
17+
last_filepath=$filepath
18+
fi
19+
if [ -e "$(dirname "$filepath")/${link%%#*}" ]; then
20+
printf " ${green}OK${reset} ${cyan}%s${reset}\n" "$link"
21+
else
22+
printf "${red}FAIL${reset} ${yellow}%s${reset}\n" "$link" >&2
23+
status=1
24+
fi
25+
done < <(
26+
git --no-pager grep --no-color -I -o -E \
27+
'\[[^]]+\]\([^)]*/[^)]*\)|href="[^"]*/[^"]*"' \
28+
-- '*' \
29+
':(exclude).*' \
30+
':(exclude)**/.*' \
31+
':(exclude)**/*.lock' \
32+
':(exclude)**/*.svg' \
33+
':(exclude)**/*.xml' \
34+
':(exclude)**/third-party/**' \
35+
| grep -Ev 'https?://' \
36+
| sed -E \
37+
-e 's#([^:]+):\[[^]]+\]\(([^)]+)\)#\1:\2#' \
38+
-e 's#([^:]+):href="([^"]+)"#\1:\2#' \
39+
-e 's/[[:punct:]]*$//' \
40+
|| true
41+
)
42+
43+
exit $status

0 commit comments

Comments
 (0)