From f89951aac4084509f66a02f9f3aa1e704fc51da1 Mon Sep 17 00:00:00 2001 From: Mandel Olaiya Date: Sun, 3 May 2026 01:35:14 +0200 Subject: [PATCH] ci: only block multilingual audit on enabled locales --- scripts/multilingual_audit_ci.py | 45 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/scripts/multilingual_audit_ci.py b/scripts/multilingual_audit_ci.py index 932bfc7..ff06cdc 100755 --- a/scripts/multilingual_audit_ci.py +++ b/scripts/multilingual_audit_ci.py @@ -19,6 +19,31 @@ def locale_rows(payload: dict) -> list[tuple[str, dict]]: summary = payload.get("summary", {}) return [(locale, data) for locale, data in summary.items() if locale != "snippets"] +def enabled_locales() -> set[str] | None: + """Return the locales this project actually enables, or None if unknown. + + Jenkins runs this repo for the `mandelstudio` staging site. We only want CI to + block on locales that are enabled for this project, otherwise a broken + translation (or an intentionally disabled locale) can keep the pipeline red. + """ + + config_path = PROJECT_ROOT / "mandelstudio" / "ocyan.json" + if not config_path.exists(): + return None + try: + payload = load_json(config_path) + except Exception: + return None + + languages = ( + (payload.get("settings") or {}) + .get("i18n", {}) + .get("languages") + ) + if not isinstance(languages, list): + return None + return {str(code) for code in languages if code} + def print_error(payload: dict) -> int: error = payload.get("error") @@ -28,7 +53,7 @@ def print_error(payload: dict) -> int: return 0 -def print_summary(payload: dict) -> tuple[int, int]: +def print_summary(payload: dict, *, enabled: set[str] | None) -> tuple[int, int]: total_block = 0 total_warn = 0 for locale, data in locale_rows(payload): @@ -36,12 +61,15 @@ def print_summary(payload: dict) -> tuple[int, int]: block = int(sev.get("block", 0) or 0) warn = int(sev.get("warn", 0) or 0) log = int(sev.get("log", 0) or 0) - total_block += block - total_warn += warn + included = enabled is None or locale in enabled + if included: + total_block += block + total_warn += warn + suffix = "" if included else " (ignored)" print( f"LOCALE {locale}: issues_found={data.get('issues_found', 0)} " f"issues_remaining={data.get('remaining_issues', 0)} " - f"block={block} warn={warn} log={log}" + f"block={block} warn={warn} log={log}{suffix}" ) return total_block, total_warn @@ -51,12 +79,14 @@ def _cta_issue_is_allowed_now(locale: str, issue: dict) -> bool: return issue.get("severity") == "block" and issue.get("issue_type") == "cta_language_mismatch" -def effective_block_count(payload: dict) -> tuple[int, int]: +def effective_block_count(payload: dict, *, enabled: set[str] | None) -> tuple[int, int]: """Return (effective_block, ignored_block) after applying allowlists.""" ignored = 0 block = 0 issues = payload.get("issues") or {} for locale, data in locale_rows(payload): + if enabled is not None and locale not in enabled: + continue locale_issues = issues.get(locale) or [] for issue in locale_issues: if issue.get("severity") != "block": @@ -103,11 +133,12 @@ def main() -> int: args = parser.parse_args() current = load_json(Path(args.json)) + enabled = enabled_locales() error_status = print_error(current) if error_status: return error_status - total_block, total_warn = print_summary(current) - effective_block, ignored_block = effective_block_count(current) + total_block, total_warn = print_summary(current, enabled=enabled) + effective_block, ignored_block = effective_block_count(current, enabled=enabled) if ignored_block: print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules")