From a310656e1d749cb094e11bed9669f362a1125db4 Mon Sep 17 00:00:00 2001 From: Benedikt Seidl Date: Tue, 14 Nov 2023 06:42:46 +0100 Subject: [PATCH] add cmk.werks.validate module this can be used via master daily docker image, to check if werks will be valid with master branch loading/parsing logic. It has to be tested in master daily docker image as this is the code used to build werk db for homepage and send mails to mailinglists. CMK-15097 Change-Id: Ibae96a5d8635d7c46804d04e87a81836fa99f6a3 --- packages/cmk-werks/cmk/werks/validate.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packages/cmk-werks/cmk/werks/validate.py diff --git a/packages/cmk-werks/cmk/werks/validate.py b/packages/cmk-werks/cmk/werks/validate.py new file mode 100644 index 00000000000..7c785ade260 --- /dev/null +++ b/packages/cmk-werks/cmk/werks/validate.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# Copyright (C) 2023 Checkmk GmbH - License: GNU General Public License v2 +# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and +# conditions defined in the file COPYING, which is part of this source code package. + +# used as validator for 2.2.0 and 2.1.0 branches + +import os +from pathlib import Path + +from . import load_werk + + +def main() -> None: + if changed_werk_files := os.environ.get("CHANGED_WERK_FILES"): + werks_to_check = (Path(line) for line in changed_werk_files.split("\n") if line) + else: + werks_to_check = ( + path + for path in Path(".werks").iterdir() + if path.name.isdigit() or path.name.endswith(".md") + ) + + for werk_path in werks_to_check: + werk_content = werk_path.read_text(encoding="utf-8") + try: + load_werk(file_content=werk_content, file_name=werk_path.name) + except Exception as e: + raise RuntimeError(f"Error while loading werk {werk_path}\n{werk_content}") from e + + +if __name__ == "__main__": + main()