From 845d4d0522f063dde7e84b281c0b191de1a43dee Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 13:50:49 +0200 Subject: ci: enable code quality reporting --- .gitlab-ci.yml | 10 ++++++++- scripts/ci/parse_clang_tidy.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/ci/parse_clang_tidy.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26e474e..01424bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,13 @@ build:bht: script: - cmake --preset bht - cmake --build --preset bht-dbg + - set -o pipefail + - python3 scripts/ci/parse_clang_tidy.py build_output.txt > code-quality.json artifacts: paths: - build/bht/ + reports: + codequality: code-quality.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.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.json expire_in: 1 week parallel: diff --git a/scripts/ci/parse_clang_tidy.py b/scripts/ci/parse_clang_tidy.py new file mode 100644 index 0000000..48596de --- /dev/null +++ b/scripts/ci/parse_clang_tidy.py @@ -0,0 +1,47 @@ +import hashlib +import json +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+\[(.*?)\]$" + ) + + 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" + + fingerprint_data = f"{path}:{line}:{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 ") + + issues = parse_clang_tidy(sys.argv[1]) + print(json.dumps(issues, indent=2)) -- cgit v1.2.3 From 24232fa7db160b4e7b702345e0892906dcccd8cd Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 14:08:13 +0200 Subject: bht: improve catch2 configuration --- CMakeLists.txt | 2 ++ CMakePresets.json | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) 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": [ -- cgit v1.2.3 From b92418534cb0018dec43349f6d72f64a5b6e18db Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 14:11:44 +0200 Subject: ci: add missing redirection --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01424bd..ebb2b8a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ 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.json artifacts: -- cgit v1.2.3 From de8efd2af75a8d8d5dd4b0b5c125d006bf7f1ba9 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 14:26:52 +0200 Subject: ci: fix code quality file paths --- scripts/ci/parse_clang_tidy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/ci/parse_clang_tidy.py b/scripts/ci/parse_clang_tidy.py index 48596de..6167c99 100644 --- a/scripts/ci/parse_clang_tidy.py +++ b/scripts/ci/parse_clang_tidy.py @@ -1,5 +1,6 @@ import hashlib import json +import os import re import sys @@ -9,6 +10,7 @@ def parse_clang_tidy(log_file_path: str) -> list[dict]: 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: @@ -19,7 +21,12 @@ def parse_clang_tidy(log_file_path: str) -> list[dict]: path, line, column, severity, message, name = match.groups() severity = "minor" if severity == "warning" else "major" - fingerprint_data = f"{path}:{line}:{name}" + try: + path = os.path.relpath(path, repo_root) + except ValueError: + pass + + fingerprint_data = f"{path}:{line}:{name}:{message}" fingerprint = hashlib.sha256(fingerprint_data.encode()).hexdigest() issues.append( -- cgit v1.2.3 From a7ba17a11c17c9975e7dc2233264913aa2e79538 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 14:31:17 +0200 Subject: ci: improve code quality fingerprints --- scripts/ci/parse_clang_tidy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/parse_clang_tidy.py b/scripts/ci/parse_clang_tidy.py index 6167c99..ec51d77 100644 --- a/scripts/ci/parse_clang_tidy.py +++ b/scripts/ci/parse_clang_tidy.py @@ -26,7 +26,7 @@ def parse_clang_tidy(log_file_path: str) -> list[dict]: except ValueError: pass - fingerprint_data = f"{path}:{line}:{name}:{message}" + fingerprint_data = f"{path}:{line}:{column}:{message}:{name}" fingerprint = hashlib.sha256(fingerprint_data.encode()).hexdigest() issues.append( -- cgit v1.2.3 From e381b49caf9d29f405cb8c9d7c2b81640135d3ba Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 18 May 2026 14:39:27 +0200 Subject: ci: generate unique quality report names --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ebb2b8a..774708b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,12 +5,12 @@ build:bht: - cmake --preset bht - 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.json + - python3 scripts/ci/parse_clang_tidy.py build_output.txt > code-quality-bht.json artifacts: paths: - build/bht/ reports: - codequality: code-quality.json + codequality: code-quality-bht.json expire_in: 5 min build:bootable: @@ -20,7 +20,7 @@ build:bootable: - cmake --preset $PLATFORM - 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.json + - 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: @@ -29,7 +29,7 @@ build:bootable: - kernel.sym - kernel.iso reports: - codequality: code-quality.json + codequality: code-quality-$PLATFORM-$TYPE.json expire_in: 1 week parallel: -- cgit v1.2.3