Merge branch 'chore/gitlab-ci-code-report' into 'main'

Add CI Job to convert checkstyle report to code quality report displayable in MR

See merge request cs108-fs26/Gruppe-13!19
This commit was merged in pull request #175.
This commit is contained in:
Lars Simon Winzer
2026-03-14 09:20:33 +01:00
2 changed files with 50 additions and 2 deletions
+21 -2
View File
@@ -1,5 +1,6 @@
stages: stages:
- lint - lint
- report
- build - build
# Reusable definitions # Reusable definitions
@@ -17,16 +18,34 @@ checkstyle:
image: gradle:9.3.1-jdk25 image: gradle:9.3.1-jdk25
script: script:
- gradle checkstyleMain checkstyleTest - gradle checkstyleMain checkstyleTest
allow_failure: true
artifacts: artifacts:
when: always when: always
paths: paths:
- build/reports/checkstyle/main.html - build/reports/checkstyle/main.html
- build/reports/checkstyle/test.html - build/reports/checkstyle/main.xml
- build/reports/checkstyle/test.html
- build/reports/checkstyle/test.xml
expose_as: 'Checkstyle Report' expose_as: 'Checkstyle Report'
expire_in: 1 week expire_in: 1 week
rules: rules:
- when: manual - when: manual
checkstyle-report:
stage: report
image: python:3.14
needs:
- job: checkstyle
artifacts: true
optional: true
script:
- python3 scripts/convert-checkstyle-gl-report.py
artifacts:
when: always
reports:
codequality: gl-code-quality-report.json
expire_in: 1 week
compile-check: compile-check:
<<: *gradle-cache <<: *gradle-cache
stage: build stage: build
+29
View File
@@ -0,0 +1,29 @@
# Skript to convert findings of checkstyle into code quality report for gitlab
import xml.etree.ElementTree as ET, json, hashlib
findings = []
for source in ["main", "test"]:
try:
tree = ET.parse(f"build/reports/checkstyle/{source}.xml")
for file in tree.findall("file"):
path = file.get("name")
for error in file.findall("error"):
line = int(error.get("line", 1))
msg = error.get("message", "")
fingerprint = hashlib.md5(f"{path}{line}{msg}".encode()).hexdigest()
findings.append({
"type": "issue",
"check_name": error.get("source", "checkstyle"),
"description": msg,
"severity": "minor",
"fingerprint": fingerprint,
"location": {
"path": "src/" + path.split("/src/")[1] if "/src/" in path else path,
"lines": {"begin": line}
}
})
except FileNotFoundError:
pass
with open("gl-code-quality-report.json", "w") as f:
json.dump(findings, f)