feat: add validate-html - Nu Html Checker as a job service instead of validator.w3.org
Test validate-html / validate-html (pull_request) Successful in 37s
Test validate-html / validate-html (pull_request) Successful in 37s
This commit is contained in:
6 files changed
+121
No files matched your search
@@ -0,0 +1,53 @@
|
||||
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"
|
||||
Reference in new issue
Block a user