diff options
| -rw-r--r-- | .gitlab-ci.yml | 10 | ||||
| -rw-r--r-- | scripts/ci/parse_clang_tidy.py | 47 |
2 files changed, 56 insertions, 1 deletions
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 <CLANG_TIDY_LOG_PATH>") + + issues = parse_clang_tidy(sys.argv[1]) + print(json.dumps(issues, indent=2)) |
