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,37 @@
|
|||||||
|
name: Test validate-html
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- validate-html/**
|
||||||
|
- .gitea/workflows/test-validate-html.yaml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
validate-html:
|
||||||
|
name: validate-html
|
||||||
|
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
|
||||||
|
|
||||||
|
- name: Valid file passes
|
||||||
|
uses: ./validate-html
|
||||||
|
with:
|
||||||
|
files: validate-html/test/valid.html
|
||||||
|
|
||||||
|
- name: Invalid file fails
|
||||||
|
id: invalid
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./validate-html
|
||||||
|
with:
|
||||||
|
files: validate-html/test/invalid.html
|
||||||
|
|
||||||
|
- name: Expect the invalid file to fail
|
||||||
|
if: steps.invalid.outcome != 'failure'
|
||||||
|
run: |
|
||||||
|
echo "::error::validate-html accepted invalid HTML"
|
||||||
|
exit 1
|
||||||
@@ -13,6 +13,7 @@ przy pobieraniu akcji, patrz „Dostęp" niżej.
|
|||||||
| [`deploy-static-site`](deploy-static-site/) | rsync zbudowanej strony do `releases/<id>/` i atomowe `activate` przez `deploy-static` (skrypt serwera w `server/`) |
|
| [`deploy-static-site`](deploy-static-site/) | rsync zbudowanej strony do `releases/<id>/` i atomowe `activate` przez `deploy-static` (skrypt serwera w `server/`) |
|
||||||
| [`pnpm-install`](pnpm-install/) | corepack + `pnpm install` z lockfile'a, opcjonalny cache store'a |
|
| [`pnpm-install`](pnpm-install/) | corepack + `pnpm install` z lockfile'a, opcjonalny cache store'a |
|
||||||
| [`resolve-buildx-cache`](resolve-buildx-cache/) | `DOCKER_CACHE_*` z runnera → `driver-opts` i refy cache'a dla buildx |
|
| [`resolve-buildx-cache`](resolve-buildx-cache/) | `DOCKER_CACHE_*` z runnera → `driver-opts` i refy cache'a dla buildx |
|
||||||
|
| [`validate-html`](validate-html/) | walidacja HTML własnym Nu Html Checkerem (kontener usługowy `vnu`), bez limitu validator.w3.org |
|
||||||
|
|
||||||
## Jak używać
|
## Jak używać
|
||||||
|
|
||||||
|
|||||||
@@ -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