ci: only block multilingual audit on enabled locales

This commit is contained in:
2026-05-03 01:35:14 +02:00
parent 53fbc7fb38
commit f89951aac4

View File

@@ -19,6 +19,31 @@ def locale_rows(payload: dict) -> list[tuple[str, dict]]:
summary = payload.get("summary", {}) summary = payload.get("summary", {})
return [(locale, data) for locale, data in summary.items() if locale != "snippets"] 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: def print_error(payload: dict) -> int:
error = payload.get("error") error = payload.get("error")
@@ -28,7 +53,7 @@ def print_error(payload: dict) -> int:
return 0 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_block = 0
total_warn = 0 total_warn = 0
for locale, data in locale_rows(payload): 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) block = int(sev.get("block", 0) or 0)
warn = int(sev.get("warn", 0) or 0) warn = int(sev.get("warn", 0) or 0)
log = int(sev.get("log", 0) or 0) log = int(sev.get("log", 0) or 0)
total_block += block included = enabled is None or locale in enabled
total_warn += warn if included:
total_block += block
total_warn += warn
suffix = "" if included else " (ignored)"
print( print(
f"LOCALE {locale}: issues_found={data.get('issues_found', 0)} " f"LOCALE {locale}: issues_found={data.get('issues_found', 0)} "
f"issues_remaining={data.get('remaining_issues', 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 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" 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.""" """Return (effective_block, ignored_block) after applying allowlists."""
ignored = 0 ignored = 0
block = 0 block = 0
issues = payload.get("issues") or {} issues = payload.get("issues") or {}
for locale, data in locale_rows(payload): for locale, data in locale_rows(payload):
if enabled is not None and locale not in enabled:
continue
locale_issues = issues.get(locale) or [] locale_issues = issues.get(locale) or []
for issue in locale_issues: for issue in locale_issues:
if issue.get("severity") != "block": if issue.get("severity") != "block":
@@ -103,11 +133,12 @@ def main() -> int:
args = parser.parse_args() args = parser.parse_args()
current = load_json(Path(args.json)) current = load_json(Path(args.json))
enabled = enabled_locales()
error_status = print_error(current) error_status = print_error(current)
if error_status: if error_status:
return error_status return error_status
total_block, total_warn = print_summary(current) total_block, total_warn = print_summary(current, enabled=enabled)
effective_block, ignored_block = effective_block_count(current) effective_block, ignored_block = effective_block_count(current, enabled=enabled)
if ignored_block: if ignored_block:
print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules") print(f"IGNORED: {ignored_block} block issue(s) now allowed by current rules")