54 lines
1.8 KiB
YAML
54 lines
1.8 KiB
YAML
name: Validate HTML
|
|
description: >-
|
|
Validates HTML files with the Nu Html Checker (the engine behind validator.w3.org) running
|
|
as a service container of the job, so CI does not hit the public validator's rate limit (429).
|
|
|
|
inputs:
|
|
files:
|
|
description: HTML files to validate, separated by spaces or new lines (shell globs work).
|
|
required: true
|
|
validator-url:
|
|
description: Nu Html Checker endpoint; the job declares it as a service named `vnu`.
|
|
required: false
|
|
default: http://vnu:8888/
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Validate HTML
|
|
shell: sh
|
|
env:
|
|
FILES: ${{ inputs.files }}
|
|
VNU_URL: ${{ inputs.validator-url }}
|
|
# The checker is a JVM and needs a few seconds after the service starts - poll instead of
|
|
# failing the first file with "connection refused".
|
|
run: |
|
|
i=0
|
|
until curl -fs -o /dev/null "$VNU_URL"; do
|
|
i=$((i + 1))
|
|
if [ "$i" -ge 60 ]; then
|
|
echo "::error::validate-html: no Nu Html Checker at $VNU_URL (is the vnu service declared?)"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
failed=0
|
|
# FILES stays unquoted on purpose - it is a list of paths and globs.
|
|
for f in $FILES; do
|
|
if [ ! -f "$f" ]; then
|
|
echo "::error::validate-html: $f does not exist"
|
|
failed=1
|
|
continue
|
|
fi
|
|
out="$(curl -fsS -H 'Content-Type: text/html; charset=utf-8' --data-binary "@$f" "${VNU_URL}?out=gnu")"
|
|
if [ -n "$out" ]; then
|
|
printf '%s\n' "$out" | sed "s|^|$f|"
|
|
fi
|
|
if printf '%s\n' "$out" | grep -qE ': (error|fatal|non-document-error)'; then
|
|
failed=1
|
|
else
|
|
echo "ok $f"
|
|
fi
|
|
done
|
|
exit "$failed"
|