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,28 @@
|
||||
# validate-html
|
||||
|
||||
Waliduje pliki HTML własną instancją Nu Html Checkera (silnik validator.w3.org) uruchamianą
|
||||
jako kontener usługowy joba — bez limitu zapytań publicznego walidatora (HTTP 429).
|
||||
Job pada na błędach (`error`, `fatal`); ostrzeżenia (`info warning`) są tylko wypisywane.
|
||||
|
||||
```yaml
|
||||
html-validate:
|
||||
runs-on: lint
|
||||
container:
|
||||
image: git.cierzniak.it/gitea-runner/node:24
|
||||
services:
|
||||
vnu:
|
||||
image: ghcr.io/validator/validator:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: https://git.cierzniak.it/gitea-runner/actions/build-site-with-hugo@v1
|
||||
with:
|
||||
version: ${{ env.HUGO_VERSION }}
|
||||
|
||||
- uses: https://git.cierzniak.it/gitea-runner/actions/validate-html@v1
|
||||
with:
|
||||
files: public/index.html public/opinia/index.html
|
||||
```
|
||||
|
||||
Usługa musi nazywać się `vnu` (albo podaj `validator-url`). Obraz ma ~350 MB; runner
|
||||
pobiera go raz i trzyma w cache'u.
|
||||
@@ -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"
|
||||
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="pl"><head><meta charset="utf-8"><title>bad</title></head><body><div><span></div></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="pl"><head><meta charset="utf-8"><title>ok</title></head><body><p>ok</p></body></html>
|
||||
Reference in new issue
Block a user