From 738bda538095e29b7ff036b268b713627c4d81ec Mon Sep 17 00:00:00 2001 From: Nedas Date: Mon, 13 Apr 2026 11:09:32 +0200 Subject: [PATCH] Now the build script fails on build. --- build-docs.py | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/build-docs.py b/build-docs.py index 1b7d517bf..67ccbe248 100644 --- a/build-docs.py +++ b/build-docs.py @@ -23,25 +23,61 @@ import argparse import json import os +import re import shutil import subprocess import sys from pathlib import Path -def run_command(cmd: list[str], description: str, check: bool = True) -> int: - """Run a command and return exit code.""" +_DOCFX_WARNING_RE = re.compile(r': warning ', re.IGNORECASE) + + +def run_command(cmd: list[str], description: str, check: bool = True, fail_on_warnings: bool = False) -> int: + """Run a command and return exit code. + + If fail_on_warnings=True, streams output line-by-line, counts DocFX warning + diagnostics (lines matching ': warning '), and returns exit code 1 if any + are found — even when the process itself exits 0. + """ print(f"\n{'='*60}") print(f" {description}") print(f"{'='*60}") print(f"Running: {' '.join(cmd)}\n") - + + if fail_on_warnings: + warning_count = 0 + process = subprocess.Popen( + cmd, + shell=(os.name == 'nt'), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + encoding='utf-8', + errors='replace' + ) + for line in process.stdout: + print(line, end='', flush=True) + if _DOCFX_WARNING_RE.search(line): + warning_count += 1 + process.wait() + + if check and process.returncode != 0: + print(f"Error: Command failed with exit code {process.returncode}") + return process.returncode + + if warning_count > 0: + print(f"\nError: DocFX produced {warning_count} warning(s). Failing build.") + return 1 + + return process.returncode + result = subprocess.run(cmd, shell=(os.name == 'nt')) - + if check and result.returncode != 0: print(f"Error: Command failed with exit code {result.returncode}") return result.returncode - + return result.returncode @@ -110,10 +146,11 @@ def build_language(lang: str, sync: bool = False) -> int: if result != 0: return result - # Build the documentation + # Build the documentation — fail if DocFX emits any warnings return run_command( ["docfx", config_path], - f"Building {lang} documentation" + f"Building {lang} documentation", + fail_on_warnings=True )