From fab03eb8cd0a493589dce2e98d4dca7063694e3e Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 14 Jan 2022 07:34:08 +0100 Subject: [PATCH] Validate generated HTML. --- .github/workflows/antsibull-docs.yml | 6 +++++- .github/workflows/validate-html.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate-html.py diff --git a/.github/workflows/antsibull-docs.yml b/.github/workflows/antsibull-docs.yml index 66e043e8..4603dee5 100644 --- a/.github/workflows/antsibull-docs.yml +++ b/.github/workflows/antsibull-docs.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install . coverage codecov + python -m pip install . coverage codecov html5lib - name: Use antsibull-docs sphinx-init run: | @@ -59,6 +59,10 @@ jobs: run: | ./build.sh + - name: Validate HTML + run: + python .github/workflows/validate-html.py build/html/ + - name: Combine and upload coverage stats run: | coverage combine .coverage.* diff --git a/.github/workflows/validate-html.py b/.github/workflows/validate-html.py new file mode 100644 index 00000000..7af1c276 --- /dev/null +++ b/.github/workflows/validate-html.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import os +import sys + +import html5lib + + +errors = 0 +for path in sys.argv[1:]: + for dirname, _, files in os.walk(path): + for file in files: + if not file.endswith('.html'): + continue + path = os.path.join(dirname, file) + try: + parser = html5lib.HTMLParser(strict=True) + with open(path, 'rb') as f: + document = parser.parse(f) + except Exception as e: + errors += 1 + print(f'{path}: {e}') + +if errors > 0: + print(f'Found {errors} errors!') + sys.exit(1)