Skip to content

Commit

Permalink
BUG: Fix docs build broken link check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Nov 28, 2022
1 parent be1d8be commit b1dd06e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
run: time catchsegv python -m backtesting.test

- if: matrix.test-type == 'docs'
run: time catchsegv doc/build.sh
run: time catchsegv bash doc/build.sh
11 changes: 8 additions & 3 deletions doc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ echo
echo 'Testing for broken links'
echo
pushd "$BUILDROOT" >/dev/null
tree .
WEBSITE='https://kernc\.github\.io/backtesting\.py'
grep -PR '<a .*?href=' |
sed -E "s/:.*?<a .*?href=([\"'])(.*?)/\t\2/g" |
tr "\"'" '#' |
cut -d'#' -f1 |
sort -u -t$'\t' -k 2 |
sort -u |
tee >(cat 1>&2) |
python -c '
import sys
from urllib.parse import urljoin
Expand All @@ -90,9 +92,12 @@ for line in sys.stdin.readlines():
grep -v $'\t''$' |
while read -r line; do
while IFS=$'\t' read -r file url; do
url=$(python -c 'import html, sys; print(html.unescape(sys.argv[-1]))' "$url")
[ -f "$url" ] ||
curl --silent --fail --retry 5 --retry-delay 5 --user-agent 'Mozilla/5.0 Firefox 61' "$url" >/dev/null 2>&1 ||
target_file="$(python -c 'import html, sys; print(html.unescape(sys.argv[-1]))' "$url")"
echo "$target_file"
if [ -f "$target_file" ]; then continue; fi

url="${url// /%20}"
curl --silent --fail --retry 5 --retry-delay 5 --user-agent 'Mozilla/5.0 Firefox 61' "$url" >/dev/null 2>&1 ||
die "broken link in $file: $url"
done
done
Expand Down

0 comments on commit b1dd06e

Please sign in to comment.