diff --git a/.gitea/workflows/test-validate-html.yaml b/.gitea/workflows/test-validate-html.yaml new file mode 100644 index 0000000..bd1b1c8 --- /dev/null +++ b/.gitea/workflows/test-validate-html.yaml @@ -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 diff --git a/README.md b/README.md index 8998d43..065df5c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ przy pobieraniu akcji, patrz „Dostęp" niżej. | [`deploy-static-site`](deploy-static-site/) | rsync zbudowanej strony do `releases//` i atomowe `activate` przez `deploy-static` (skrypt serwera w `server/`) | | [`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 | +| [`validate-html`](validate-html/) | walidacja HTML własnym Nu Html Checkerem (kontener usługowy `vnu`), bez limitu validator.w3.org | ## Jak używać diff --git a/validate-html/README.md b/validate-html/README.md new file mode 100644 index 0000000..eca9d60 --- /dev/null +++ b/validate-html/README.md @@ -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. diff --git a/validate-html/action.yaml b/validate-html/action.yaml new file mode 100644 index 0000000..e6c8d3f --- /dev/null +++ b/validate-html/action.yaml @@ -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" diff --git a/validate-html/test/invalid.html b/validate-html/test/invalid.html new file mode 100644 index 0000000..535c100 --- /dev/null +++ b/validate-html/test/invalid.html @@ -0,0 +1 @@ +bad
diff --git a/validate-html/test/valid.html b/validate-html/test/valid.html new file mode 100644 index 0000000..3ecac16 --- /dev/null +++ b/validate-html/test/valid.html @@ -0,0 +1 @@ +ok

ok