diff options
| -rw-r--r-- | .gitlab-ci.yml | 12 | ||||
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | CMakePresets.json | 5 | ||||
| -rw-r--r-- | scripts/ci/parse_clang_tidy.py | 54 |
4 files changed, 67 insertions, 6 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26e474e..774708b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,10 +3,14 @@ build:bht: image: registry.gitlab.ost.ch:45023/teachos/devcontainers/bht.ci:latest script: - cmake --preset bht - - cmake --build --preset bht-dbg + - cmake --build --preset bht-dbg 2>&1 | tee build_output.txt + - set -o pipefail + - python3 scripts/ci/parse_clang_tidy.py build_output.txt > code-quality-bht.json artifacts: paths: - build/bht/ + reports: + codequality: code-quality-bht.json expire_in: 5 min build:bootable: @@ -14,7 +18,9 @@ build:bootable: image: registry.gitlab.ost.ch:45023/teachos/devcontainers/x86-64.ci:latest script: - cmake --preset $PLATFORM - - cmake --build --preset $PLATFORM-$TYPE + - cmake --build --preset $PLATFORM-$TYPE 2>&1 | tee build_output.txt + - set -o pipefail + - python3 scripts/ci/parse_clang_tidy.py build_output.txt > code-quality-$PLATFORM-$TYPE.json - cp build/${PLATFORM}/bin/**/kernel.{dis,elf,sym,iso} . artifacts: paths: @@ -22,6 +28,8 @@ build:bootable: - kernel.elf - kernel.sym - kernel.iso + reports: + codequality: code-quality-$PLATFORM-$TYPE.json expire_in: 1 week parallel: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d48a13..fb5b101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ if (BUILD_TESTING) find_package("Catch2") include("Catch") + + add_compile_definitions("CATCH_CONFIG_NO_COUNTER") endif() #[============================================================================[ diff --git a/CMakePresets.json b/CMakePresets.json index d5123a2..0e5dd88 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -24,10 +24,7 @@ { "name": "bht", "inherits": "base", - "description": "Build-host Testing", - "cacheVariables": { - "CATCH_CONFIG_NO_COUNTER": true - } + "description": "Build-host Testing" } ], "buildPresets": [ diff --git a/scripts/ci/parse_clang_tidy.py b/scripts/ci/parse_clang_tidy.py new file mode 100644 index 0000000..ec51d77 --- /dev/null +++ b/scripts/ci/parse_clang_tidy.py @@ -0,0 +1,54 @@ +import hashlib +import json +import os +import re +import sys + + +def parse_clang_tidy(log_file_path: str) -> list[dict]: + issues = [] + pattern = re.compile( + r"^(.*?):(\d+):(\d+):\s+(warning|error|note):\s+(.*?)\s+\[(.*?)\]$" + ) + repo_root = os.environ.get("CI_PROJECT_DIR", os.getcwd()) + + with open(log_file_path, "r") as f: + for line in f: + match = pattern.match(line) + if not match: + continue + + path, line, column, severity, message, name = match.groups() + severity = "minor" if severity == "warning" else "major" + + try: + path = os.path.relpath(path, repo_root) + except ValueError: + pass + + fingerprint_data = f"{path}:{line}:{column}:{message}:{name}" + fingerprint = hashlib.sha256(fingerprint_data.encode()).hexdigest() + + issues.append( + { + "description": f"{message} ({name})", + "fingerprint": fingerprint, + "severity": severity, + "location": { + "path": path, + "lines": { + "begin": int(line), + }, + }, + } + ) + + return issues + + +if __name__ == "__main__": + if len(sys.argv) < 2: + sys.exit("Usage: python3 parse_clang_tidy.py <CLANG_TIDY_LOG_PATH>") + + issues = parse_clang_tidy(sys.argv[1]) + print(json.dumps(issues, indent=2)) |
