Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions checks/run_a11y_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ set -euo pipefail

CACHE_DIR="${HOME}/.cache/accesslint-audit"
PORT="$(python3 -c 'import socket; s=socket.socket(); s.bind(("",0)); print(s.getsockname()[1]); s.close()')"
URLS="${1:-http://localhost:${PORT}/}"

if [ ! -d "public" ]; then
echo "Error: 'public' directory does not exist. Run a build first!" >&2
exit 1
fi

if [ -n "${1:-}" ]; then
URLS="$1"
else
# No URL given: audit every page from the built sitemap.
URLS="$(sed -n 's#.*<loc>\(.*\)</loc>.*#\1#p' public/sitemap.xml \
| sed "s#^https\?://[^/]*/#http://localhost:${PORT}/#")"
fi
Comment on lines +18 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Ahoy! Ye be blindly plunderin' public/sitemap.xml without so much as a glance to see if the map actually exists in yer 'public' port! Since ye set pipefail at the top of yer scroll, if that file be missin', yer whole vessel will scuttle itself with a nasty error. Best check if the sitemap exists first, ye scurvy dog, or suffer the wrath of the deep!

Suggested change
else
# No URL given: audit every page from the built sitemap.
URLS="$(sed -n 's#.*<loc>\(.*\)</loc>.*#\1#p' public/sitemap.xml \
| sed "s#^https\?://[^/]*/#http://localhost:${PORT}/#")"
fi
else
# No URL given: audit every page from the built sitemap.
if [ ! -f "public/sitemap.xml" ]; then
echo "Error: 'public/sitemap.xml' does not exist. Run a build first!" >&2
exit 1
fi
URLS="
$(sed -n 's#.*<loc>\(.*\)</loc>.*#\1#p' public/sitemap.xml \
| sed "s#^https\?://[^/]*/#http://localhost:${PORT}/#")"
fi


if [ ! -d "$CACHE_DIR" ]; then
git clone --depth 1 --branch v0 https://github.com/AccessLint/audit.git "$CACHE_DIR"
Expand All @@ -16,11 +28,6 @@ if [ ! -f "$READY_MARKER" ]; then
touch "$READY_MARKER"
fi

if [ ! -d "public" ]; then
echo "Error: 'public' directory does not exist. Run a build first!" >&2
exit 1
fi

python3 -m http.server "$PORT" --directory public &
SERVER_PID=$!
trap 'kill "$SERVER_PID" 2>/dev/null || true' EXIT
Expand Down
Loading